GridView.RowCommand 事件获取主键值的方法

本文详细介绍了ASP.NET中GridView控件的RowCommand事件及其使用方法。通过实例展示了如何在GridView中添加带有CommandArgument属性的模板列,并在后台代码中通过RowCommand事件处理函数来获取CommandArgument的值。

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

1. RowCommond 事件

.aspx

在GridView添加一模板列,加上CommandArgument 并绑定如下

1 < asp:GridView ID = " gvAdminList " runat = " server " >             
2 < asp:TemplateField >
3    < ItemTemplate >
4       < asp:LinkButton ID = " lbtnLook " runat = " server " CommandName = " GetAdminInfo " CommandArgument = ' <%# Eval("AdminID") %> ' > 查看 </ asp:LinkButton >
5       </ ItemTemplate >
6    </ asp:TemplateField >
7 </ asp:GridView >


.aspx.cs(C#)
读取CommandArgument

当单击 GridView 控件中的按钮时发生。

1 GridView.RowCommand 事件获取主键值的方法 - 随风漫步 - 梦想在自由的飞翔 protected void gvAdminList_RowCommand( object sender, GridViewCommandEventArgs e)
2 GridView.RowCommand 事件获取主键值的方法 - 随风漫步 - 梦想在自由的飞翔GridView.RowCommand 事件获取主键值的方法 - 随风漫步 - 梦想在自由的飞翔 GridView.RowCommand 事件获取主键值的方法 - 随风漫步 - 梦想在自由的飞翔 {
3GridView.RowCommand 事件获取主键值的方法 - 随风漫步 - 梦想在自由的飞翔  if (e.CommandName == "GetAdminInfo")
4GridView.RowCommand 事件获取主键值的方法 - 随风漫步 - 梦想在自由的飞翔GridView.RowCommand 事件获取主键值的方法 - 随风漫步 - 梦想在自由的飞翔    GridView.RowCommand 事件获取主键值的方法 - 随风漫步 - 梦想在自由的飞翔{
5GridView.RowCommand 事件获取主键值的方法 - 随风漫步 - 梦想在自由的飞翔      string AdminID = e.CommandArgument.ToString();
6GridView.RowCommand 事件获取主键值的方法 - 随风漫步 - 梦想在自由的飞翔     }

7GridView.RowCommand 事件获取主键值的方法 - 随风漫步 - 梦想在自由的飞翔}

命名空间: System.Web.UI.WebControls
程序集: System.Web(在 System.Web.dll 中)

语法
Public Event RowCommand As GridViewCommandEventHandler
Dim instance As GridView  Dim handler As GridViewCommandEventHandler    AddHandler instance.RowCommand, handler
public event GridViewCommandEventHandler RowCommand
public:   event GridViewCommandEventHandler^ RowCommand {      void add (GridViewCommandEventHandler^ value);      void remove (GridViewCommandEventHandler^ value);  }
/** @event */  public void add_RowCommand (GridViewCommandEventHandler value)  /** @event */  public void remove_RowCommand (GridViewCommandEventHandler value)
JScript 不支持事件。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值