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

来源:互联网 发布:快速通过精算师 知乎 编辑:程序博客网 时间:2024/05/18 02:49

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 控件中的按钮时发生。

1GridView.RowCommand 事件获取主键值的方法 - 随风漫步 - 梦想在自由的飞翔protectedvoid gvAdminList_RowCommand(object sender, GridViewCommandEventArgs e)
2GridView.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 不支持事件。
原创粉丝点击