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 >
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
protected
void
gvAdminList_RowCommand(
object
sender, GridViewCommandEventArgs e)
2
{
3
if (e.CommandName == "GetAdminInfo")
4
{
5
string AdminID = e.CommandArgument.ToString();
6
}
7
}

2



3

4



5

6

7

命名空间: 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 不支持事件。 |