分类: 嵌入式
2011-03-15 14:42:16
我们最常用的,当然就是RowDataBound方法了
在 GridView1_RowDataBound中获取主键的值
protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
{
int index = GridView1.DataKeys[e.Row.RowIndex].Value;
}
其次就是删除事件
在 GridView1_RowDeleting中获取主键的值
protected void GridView1_RowDeleting(object sender, GridViewDeleteEventArgs e)
{
int index=GridView1.DataKeys[e.RowIndex].Value;
}
分页事件
在 GridView1_PageIndexChanging中获取主键的值
protected void GridView1_PageIndexChanging(object sender, GridViewPageEventArgs e)
{
int index=GridView1.DataKeys[e.NewPageIndex].Value;
}
还有其它几个不常用的:
在 GridView1_RowCommand中获取主键的值:
protected void GridView1_RowCommand(object sender, GridViewCommandEventArgs e)
{
int index = GridView1.DataKeys[Convert.ToInt32(e.CommandArgument)].Value;
}
在 GridView1_RowEditing中获取主键的值
protected void GridView1_RowEditing(object sender, GridViewEditEventArgs e)
{
int index = GridView1.DataKeys[e.NewEditIndex].Value;
}
在 GridView1_RowUpdating中获取主键的值
protected void GridView1_RowUpdating(object sender, GridViewUpdateEventArgs e)
{
int index = GridView1.DataKeys[e.RowIndex].Value;
}