zoukankan      html  css  js  c++  java
  • Gridview中Datakeys 通过主键取得各列的值。(转)

    1. 首先在初始化Gridview时候定义主键的数组。

     GridViewTeacherStudent.DataKeyNames=new string[] {"courseId","studentId","type","level","unit"};

    2. 在进行删除操作,或者对某行进行操作获得列中的值。

     string studentId = GridViewTeacherStudent.DataKeys[e.RowIndex]["studentId"].ToString().Trim();

    3.如果只有单个的键值时候。如只有”StudentId“一个主键下面直接获得。

     string studentId = GridViewTeacherStudent.DataKeys[e.RowIndex].Value.ToString().Trim();

    在 GridView1_RowCommand中获取主键的值:

      protected void GridView1_RowCommand(object sender, GridViewCommandEventArgs e)

      {

      int OrderId = Convert.ToInt32(GridView1.DataKeys[Convert.ToInt32(e.CommandArgument)].Value); }

      在 GridView1_PageIndexChanging中获取主键的值

      protected void GridView1_PageIndexChanging(object sender, GridViewPageEventArgs e)

      {

      int index=GridView1.DataKeys[e.NewPageIndex].Value;

      }

      在 GridView1_RowDeleting中获取主键的值

      protected void GridView1_RowDeleting(object sender, GridViewDeleteEventArgs e)

      {

      int index=GridView1.DataKeys[e.RowIndex].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;

      }

      在 GridView1_RowDataBound中获取主键的值

      protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)

      {

      int index = GridView1.DataKeys[e.Row.RowIndex].Value;

      }

    原文地址 :http://www.cnblogs.com/LifeKingcn/archive/2012/08/21/2649380.html

  • 相关阅读:
    jieba的使用
    如何用python查看自己的电脑有几个核
    NLTK实现文本切分
    nltk的安装和简单使用
    初识NLP 自然语言处理
    mysql 查询存在A表中而不存在B表中的数据
    mysql 导出数据报错: row must be in range 0-65535
    python3 re模块正则匹配字符串中的时间信息
    Python语法速查: 14. 测试与调优
    Python语法速查: 20. 线程与并发
  • 原文地址:https://www.cnblogs.com/lczblog/p/4128639.html
Copyright © 2011-2022 走看看