zoukankan      html  css  js  c++  java
  • 如何取GridView中隐藏列的值

    最近在做一个项目时,有一个要求是选择GRIDVIEW列表中的项(通过CHECKBOX),然后删除所选择的数据

    代码如下:

        /// <summary>
        /// 摘要:删除单据明细列表中选择的明细信息
        /// 创建人:贺振军
        /// 创建日期:2009.07.09
        /// </summary>
        private void DelDjMx()
        {
            foreach (GridViewRow row in this.gvordermx.Rows)
            {
                CheckBox chk = (CheckBox)row.Cells[0].FindControl("chkrow");

                if (chk.Checked == true)
                {
                    //删除临时表中的数据
                    string strpk = row.Cells[1].Text

                    ordermx.Table_Dele_Temp(strpk);

                }
            }

            this.gvordermx.DataSource = ordermx.TempTabl;

            this.gvordermx.DataBind();
        }

          在运行时发现因为第二列我做成隐藏列,所以使用 row.Cells[1].Text 永远取到的都是空值(原来VS2003可能可以取到,但VS2008,VS2005不能取),经过测试可以将这一列设置为关键字列即 DataKey = "XH",然后将此列隐藏即可,列值就可以通过下面的代码即可取得。

        /// <summary>
        /// 摘要:删除单据明细列表中选择的明细信息
        /// 创建人:贺振军
        /// 创建日期:2009.07.09
        /// </summary>
        private void DelDjMx()
        {
            foreach (GridViewRow row in this.gvordermx.Rows)
            {
                CheckBox chk = (CheckBox)row.Cells[0].FindControl("chkrow");

                if (chk.Checked == true)
                {
                    //删除临时表中的数据
                    string strpk = gvordermx.DataKeys[row.RowIndex].Value.ToString();

                    ordermx.Table_Dele_Temp(strpk);

                }
            }

            this.gvordermx.DataSource = ordermx.TempTabl;

            this.gvordermx.DataBind();
        }

    特此记录一下

  • 相关阅读:
    spring boot 配置示例
    MyBatis 常用标签用法
    http请求头部常用参数
    CentOS7使用firewalld打开关闭防火墙与端口
    java8 base64
    MD5工具类
    各种远程登录工具
    MySql 常用命令
    spring-boot-mybaits 开启事务
    springboot 项目打包到 linux下无法 运行
  • 原文地址:https://www.cnblogs.com/hzj3099/p/1520013.html
Copyright © 2011-2022 走看看