VS2012环境
1.通过CommandName属性触发事件:
<asp:ButtonField ImageUrl="~/Images/edit.png" Text="编辑" HeaderText="编辑" ButtonType="Image" CommandName="editClick" >
2.直接通过CommandArgument获取操作行号和主键值:
在protected void GridView1_RowCommand(object sender, GridViewCommandEventArgs e){
if (e.CommandName.ToString() == ("editClick")) {int rowindex = Convert.ToInt32(e.CommandArgument.ToString());
string id = GridView1.DataKeys[rowindex].Value.ToString();
Response.Write("<script>alert('" + id + "')</script>");
}
}