GridView1_RowCommand事件是GridView中生成事件时激发

比如说页面中有一个按钮给他设置CommandName属性

<asp:Button ID="btnCheHui" runat="server" class="btn btn-primary" Text="撤回流程" OnClientClick="return confirm('你确定要撤回流程吗')"  CommandName="CheHui" />

那么在后置代码中的GridView1_RowCommand事件中:

 protected void GridView1_RowCommand(object sender, GridViewCommandEventArgs e)
 {

    //得到选中行的索引
            GridViewRow gvr = (GridViewRow)((Button)e.CommandSource).Parent.Parent;
            int autoId = Convert.ToInt32(this.GridView1.DataKeys[gvr.RowIndex].Value);

    

    //判断当前的按钮命令

    if (e.CommandName == "CheHui")
            {

        //根据获取到的主键autoId值修改数据

    }
             

  GridView1_RowCommand中取到GridView中其他值:

获取第一个值  string zhi = GridView1.Rows[gvr.RowIndex].Cells[0].Text;

获取主键的值  int id = Convert.ToInt32(e.CommandArgument.ToString());

 

相关文章:

  • 2022-12-23
  • 2022-12-23
  • 2021-11-15
  • 2022-12-23
  • 2021-10-31
  • 2021-11-15
  • 2021-05-28
猜你喜欢
  • 2021-10-20
  • 2021-10-15
  • 2021-06-03
  • 2021-12-08
  • 2022-12-23
  • 2021-08-24
相关资源
相似解决方案