Click here to Skip to main content
11,706,803 members (52,962 online)
Rate this: bad
good
Please Sign up or sign in to vote.
See more: ASP.NET C#4.0
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();
    }
 
       }
Posted 8-Jan-13 21:44pm
mrDivan1.1K
Edited 8-Jan-13 22:47pm
v2
Comments
Sandeep Mewara at 9-Jan-13 4:05am
   
Not clear. What are you trying? Please elaborate.
mrDivan at 9-Jan-13 5:24am
   
thanks for your response Sandeep im trying to write the edited value of celldata back to the in memmory table for that row
mrDivan at 9-Jan-13 4:40am
   
Hi im trying to change the value of celldata and then write that back to the datatable(in memmry)

1 solution

Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

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

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
0 OriginalGriff 146
1 Sergey Alexandrovich Kryukov 115
2 chainerlt 110
3 Mika Wendelius 80
4 ppolymorphe 71
0 OriginalGriff 9,190
1 Sergey Alexandrovich Kryukov 8,407
2 CPallini 5,189
3 Maciej Los 4,756
4 Mika Wendelius 3,686


Advertise | Privacy | Mobile
Web01 | 2.8.150819.1 | Last Updated 9 Jan 2013
Copyright © CodeProject, 1999-2015
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100