1、在Gridview中添加模板列,在其中加入Linkbuttion,增加CommandName属性(设置命令名),并赋值

       <asp:TemplateField HeaderText="记录编号">
          <ItemTemplate>
             <asp:LinkButton ID="lbtnRecordid" CommandName="lbtn" runat="server" ForeColor="Blue" Text='<%# DataBinder.Eval(Container.DataItem,"recordid") %>'></asp:LinkButton>
         </ItemTemplate>
      </asp:TemplateField>

    2、在Gridview的RowCommand事件中加入代码,例如:

      protected void GridView1_RowCommand(object sender, GridViewCommandEventArgs e)
     {
        if (e.CommandName == "lbtn")
        {
            GridViewRow gvrow = (GridViewRow)(((LinkButton)e.CommandSource).NamingContainer); //获取被点击的linkButton所在的GridViewRow
            int index = gvrow.RowIndex; //获取到行索引 RowIndex
            
            //获取当前行的某列值
            string userid=GridView1.Rows[index].Cells[列索引].Text.Trim();

            ......

        }     
       }

     

相关文章:

  • 2022-12-23
  • 2022-12-23
  • 2022-02-28
  • 2022-12-23
  • 2022-12-23
  • 2021-10-11
  • 2021-10-08
猜你喜欢
  • 2021-08-19
  • 2022-02-11
  • 2022-12-23
  • 2021-05-19
  • 2022-01-19
  • 2021-05-29
相关资源
相似解决方案