获取gridview中单击列的列索引

时间:2016-08-05 10:18:38

标签: c# asp.net vb.net gridview rowcommand

点击页脚中的按钮时,如何检查HeaderTextColumnIndex或点击的列?

enter image description here

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

1 个答案:

答案 0 :(得分:0)

列已由命令名

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