首页新闻找找看学习计划

DataGridView 刷新前记录选中的多行值, 然后刷新后在赋值回去!记录选中行

0
悬赏园豆:30 [已解决问题] 解决于 2011-12-22 16:49

DataGridView 刷新前记录选中的多行值, 然后刷新后在赋值回去!记录选中行

~@@~的主页 ~@@~ | 初学一级 | 园豆:35
提问于:2011-12-15 10:58
< >
分享
最佳答案
0

  List<VoucherDetailItem> voucher = new List<VoucherDetailItem>();

        Dictionary<int, decimal> dict = (Dictionary<int, decimal>)ViewState["products"];

        //查询所有产品信息。
        foreach (GridViewRow row in this.gvProduct.Rows)
        {
            CheckBox cbx = (CheckBox)row.Cells[0].FindControl("cbxChoose");

            //判断是否为用户选择的产品。
            if (cbx.Checked)
            {
                //判断是否包含已选产品。
                if (!dict.ContainsKey(row.DataItemIndex))
                {
                    dict.Add(row.DataItemIndex, 0m);
                }

                DataKey dataKey = this.gvProduct.DataKeys[row.DataItemIndex];

                VoucherDetailItem voucherItem = new VoucherDetailItem();
                voucherItem.F_GUID = Guid.Parse(dataKey["F_GUID"].ToString());
                voucherItem.F_GoodsName = dataKey["F_GoodsName"].ToString();
                voucherItem.F_TypeName = dataKey["F_TypeName"].ToString();
                voucherItem.F_SuppliersGoodsGUID = Guid.Parse(dataKey["F_SuppliersGoodsGUID"].ToString());
                voucherItem.F_Count = Decimal.Parse(dataKey["F_Count"].ToString());
                voucherItem.fCount = dict[row.DataItemIndex];

                voucher.Add(voucherItem);
            }
            else
            {
                if (dict.ContainsKey(row.DataItemIndex))
                {
                    dict.Remove(row.DataItemIndex);
                }
            }
        }

        //出库数量和出库的金额。
        this.gvVoucher.DataKeyNames = new string[] { "F_GoodsName", "F_Guid", "F_SuppliersGoodsGUID", "F_Count", "F_TypeName", "fCount" };

        this.gvVoucher.DataSource = voucher;
        this.gvVoucher.DataBind();

 

  private void refreshViewState()
    {
        Dictionary<int, decimal> dict = (Dictionary<int, decimal>)ViewState["products"];

        foreach (GridViewRow row in this.gvVoucher.Rows)
        {
            KeyValuePair<int, decimal> item = dict.ElementAt<KeyValuePair<int, decimal>>(row.DataItemIndex);

            TextBox tbx = (TextBox)row.Cells[6].FindControl("txtCount");
            decimal result = 0m;
            if (Decimal.TryParse(tbx.Text, out result))
            {
                dict[item.Key] = result;
            }
        }
    }

收获园豆:30
悟行 | 专家六级 |园豆:12161 | 2011-12-15 11:07
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册