GridView中的GridView1_RowCommand事件

本文详细介绍了ASP.NET中GridView控件的RowCommand事件使用方法,包括如何通过CommandName属性触发事件,以及如何在事件处理程序中获取所选行的数据。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

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());

 

转载于:https://www.cnblogs.com/yuanyanyan/p/5412589.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值