在线时间:8:00-16:00
迪恩网络APP
随时随地掌握行业动态
扫描二维码
关注迪恩网络微信公众号
1、后台任意一个位置获取GridView行的主键值
foreach (GridViewRow row in GridView1.Rows) { string order_Id=this.GridView1.DataKeys[row.RowIndex]["orders_Id"].ToString(); }
2、RowDataBound方法中,在 GridView_RowDataBound中获取主键的值
protected void GridView_RowDataBound(object sender, GridViewRowEventArgs e) { int index = GridView.DataKeys[e.Row.RowIndex].Value; }
3、其次就是删除事件,在 GridView_RowDeleting中获取主键的值 protected void GridView_RowDeleting(object sender, GridViewDeleteEventArgs e) { int index = GridView1.DataKeys[e.RowIndex].Value; }
4、分页事件,在 GridView_PageIndexChanging中获取主键的值 protected void GridView_PageIndexChanging(object sender, GridViewPageEventArgs e) { int index = GridView.DataKeys[e.NewPageIndex].Value; }
5、行命令事件,在 GridView_RowCommand中获取主键的值: protected void GridView_RowCommand(object sender, GridViewCommandEventArgs e) { int index = GridView.DataKeys[Convert.ToInt32(e.CommandArgument)].Value; } 或 GridViewRow row= ((GridViewRow)(((LinkButton)(e.CommandSource)).Parent.Parent));
int id=Convert.ToInt32(GridView.DataKeys[row.RowIndex].Value);
6、行编辑事件,在 GridView_RowEditing中获取主键的值 protected void GridView_RowEditing(object sender, GridViewEditEventArgs e) { int index = GridView.DataKeys[e.NewEditIndex].Value; }
7、行更新事件,在 GridView_RowUpdating中获取主键的值 protected void GridView_RowUpdating(object sender, GridViewUpdateEventArgs e) { int index = GridView.DataKeys[e.RowIndex].Value; }
|
请发表评论