简体   繁体   中英

Get column index of clicked column in gridview

When a button in the footer is clicked how can the HeaderText or ColumnIndex or the clicked column be checked?

在此处输入图片说明

GRIDVIEW

  <asp:GridView ID="gv" runat="Server" ShowFooter="true">
    <Columns>
      <asp:TemplateField HeaderText="1">
        <ItemTemplate></ItemTemplate>
        <FooterTemplate>
          <asp:LinkButton ID="btnSubmit1" runat="server" CommandName="Submit1">SUBMIT</asp:LinkButton>
        </FooterTemplate>
      </asp:TemplateField>

      <asp:TemplateField HeaderText="2">
        <ItemTemplate></ItemTemplate>
        <FooterTemplate>
          <asp:LinkButton ID="btnSubmit2" runat="server" CommandName="Submit2">SUBMIT</asp:LinkButton>
        </FooterTemplate>
      </asp:TemplateField>

      <asp:TemplateField HeaderText="3">
        <ItemTemplate></ItemTemplate>
        <FooterTemplate>
          <asp:LinkButton ID="btnSubmit3" runat="server" CommandName="Submit3">SUBMIT</asp:LinkButton>
        </FooterTemplate>
      </asp:TemplateField>
    </Columns>
  </asp:GridView>

VB.NET

  Private Sub gv_RowCommand(sender As Object, e As GridViewCommandEventArgs) Handles gv.RowCommand
    If e.CommandName = "Submit1" Then

      'GET CLICKED BUTTON
      Dim Button = TryCast(e.CommandSource, LinkButton)
      'GET CLICKED ROW
      Dim Row = TryCast(Button.NamingContainer, GridViewRow)
      'GET CLICKED COLUMN
      '?
      'GET CLICKED COLUMN HEADER TEXT
      '?

    End If
  End Sub

列已由命令名称确定

Dim Column As String = sender.Columns(0).HeaderText

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM