zoukankan      html  css  js  c++  java
  • Asp.Net 之 获取GridView行的DataKeys

    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;
     }
  • 相关阅读:
    Ubuntu 14.04 LTS 系统空间不足,输入密码后,无法进入桌面的解决办法
    语言代码表
    在WPS中删除整行的快捷键是什么?
    Google浏览器&插件
    Linux命令大全
    Python下载安装
    Tiobe最新编程语言排行
    windows 清理利器
    如何用VBA实现格式刷的功能?
    武侠音乐精装
  • 原文地址:https://www.cnblogs.com/xinaixia/p/4990561.html
Copyright © 2011-2022 走看看