本文介绍了将已编辑的行值保存回inmemmory数据表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何将更改后的值保存回内存表中请帮助







how do i save the changed value back to the in memmory table please help



protected void btnFixZero(object sender, EventArgs e)
{
    System.Data.DataTable dt = new System.Data.DataTable();
    dt = (System.Data.DataTable)ViewState["SelectedRecords"];
    int rowscount = GridView2.Rows.Count;
    int columnscount = GridView2.Columns.Count;
    if (missingCell == 0)
    {
        foreach (DataRow row in dt.Rows)
        {

            string cellData = row["F4"].ToString();
            string sub0 = cellData.Substring(0, 1);
            string sub1 = cellData.Substring(1, 1);
            string subplus = cellData.Substring(0, 1);
    
            if (sub0 == "2" && sub1 == "7")
            {
                cellData = cellData.Remove(0, 2);
                cellData = "0" + cellData;
                row.AcceptChanges();
                dt.AcceptChanges();
            }
            if (sub0 != "0")
            {
                cellData = "0" + cellData;
                row.AcceptChanges();
                dt.AcceptChanges();
            }

        }
        ViewState["SelectedRecords"] = dt;


        GridView2.DataSource = dt;
        GridView2.DataBind();
    }

       }

推荐答案

protected void btnFixZero(object sender, EventArgs e)
      {
          System.Data.DataTable dt = new System.Data.DataTable();
          dt = (System.Data.DataTable)ViewState["SelectedRecords"];
          int rowscount = GridView2.Rows.Count;
          int columnscount = GridView2.Columns.Count;
          if (missingCell == 0)
          {
              foreach (DataRow row in dt.Rows)
              {

                  string cellData = row["F4"].ToString();
                  string sub0 = cellData.Substring(0, 1);
                  string sub1 = cellData.Substring(1, 1);
                  string subplus = cellData.Substring(0, 1);

                  if (sub0 == "2" && sub1 == "7")
                  {
                      cellData = cellData.Remove(0, 2);
                      cellData = "0" + cellData;
                      row["F4"] = cellData;//had to specify which column
                      row.AcceptChanges();
                      dt.AcceptChanges();
                  }
                  if (sub0 != "0")
                  {
                      cellData = "0" + cellData;
                      row["F4"] = cellData;//had to specify which column
                      row.AcceptChanges();
                      dt.AcceptChanges();
                  }

              }
              dt.AcceptChanges();
              ViewState["SelectedRecords"] = dt;


              GridView2.DataSource = dt;
              GridView2.DataBind();
          }

             }


这篇关于将已编辑的行值保存回inmemmory数据表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-26 12:10