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();
        }

    特此记录一下

  • 相关阅读:
    百度之星资格赛1001——找规律——大搬家
    HDU1025——LIS——Constructing Roads In JGShining's Kingdom
    DP(递归打印路径) UVA 662 Fast Food
    递推DP UVA 607 Scheduling Lectures
    递推DP UVA 590 Always on the run
    递推DP UVA 473 Raucous Rockers
    博弈 HDOJ 4371 Alice and Bob
    DFS(深度) hihoCoder挑战赛14 B 赛车
    Codeforces Round #318 [RussianCodeCup Thanks-Round] (Div. 2)
    DP(DAG) UVA 437 The Tower of Babylon
  • 原文地址:https://www.cnblogs.com/hzj3099/p/1520013.html
Copyright © 2011-2022 走看看