Click here to Skip to main content
15,917,454 members
Please Sign up or sign in to vote.
2.00/5 (2 votes)
See more:
Hi all ,
Please help me

This is my code, Please review the code :-


C#
insertplannedgangs inp = new insertplannedgangs(); // object class 
    insertplannedfore inf = new insertplannedfore(); // object class 
    DataTable dt;
   
   
    protected void Page_Load(object sender, EventArgs e)
    {
   
       
    }


    protected void Butshow_Click(object sender, EventArgs e)
    {
        DateTime datefrom = DateTime.Parse(Textfrom.Text);// textbox for date from
        DateTime dateto = DateTime.Parse(Textto.Text);// textbox for date to 

        // get date in gridview 
        inp.plandatefrom = datefrom;
        inp.plandateto = dateto;
        dt = inp.gridshow(); // this method used stored peocedure that take from and to date to get date between and worked well 
        GridView1.DataSource = dt;
        GridView1.DataBind();
       
// here I want to get other value using the  date output from previous datatable "dt"
         foreach (DataRow row in dt.Rows)
        {
       
      DataTable grid = new DataTable();
        DataTable dtf = new DataTable();
       
            inf.plandat = DateTime.Parse(row[0].ToString()); 
            grid = inf.gridshowfor();// this method take the date and get result

          inf.plandat = DateTime.Parse(row[0].ToString());
            grid = inf.gridshowfor();

            GridView2.DataSource = grid;
            GridView2.DataBind(); // here is the problem , the result get one value "last value saved in datatable " 

                
         }
    }
  
    }
Posted
Updated 25-Aug-13 23:49pm
v3
Comments
Azziet 26-Aug-13 5:58am    
Mr. shms_rony...actually i didn't understand your problem..can you please elaborate...
shms_rony 26-Aug-13 6:03am    
grid datatable get the last value

if you have x = 0 and save 1 in x
automatically 0 deleted

this happened in datatable
i want to save each value in one row in datatable
Azziet 26-Aug-13 6:16am    
you have written same statement two times..

inf.plandat = DateTime.Parse(row[0].ToString());
grid = inf.gridshowfor();// this method take the date and get result

inf.plandat = DateTime.Parse(row[0].ToString());
grid = inf.gridshowfor();

and you have not assigned the date.inf.plandat to your function inf.gridshowfor()..

check the function inf.gridshowfor()...

1 solution

Update Your Butshow_Click event as Mentioned Below :

C#
protected void Butshow_Click(object sender, EventArgs e)
      {
          DateTime datefrom = DateTime.Parse(Textfrom.Text);// textbox for date from
          DateTime dateto = DateTime.Parse(Textto.Text);// textbox for date to 
      
          // get date in gridview 
          inp.plandatefrom = datefrom;
          inp.plandateto = dateto;
          dt = inp.gridshow(); // this method used stored peocedure that take from and to date to get date between and worked well 
          GridView1.DataSource = dt;
          GridView1.DataBind();
      
          // here I want to get other value using the  date output from previous datatable "dt"
      
          DataTable grid = new DataTable();
          foreach (DataRow row in dt.Rows)
          {
              DataTable dtf = new DataTable();
      
              inf.plandat = DateTime.Parse(row[0].ToString());
              grid = inf.gridshowfor();// this method take the date and get result
              inf.plandat = DateTime.Parse(row[0].ToString());
      
              dtf = inf.gridshowfor();

              if (grid.Rows.Count == 0)
              {
                  grid = dtf;
              }
              else
              {
                  foreach (var rowToAdd in dtf.Rows)
                  {
                      grid.Rows.Add(rowToAdd);
                  }
              }
          }
      
          GridView2.DataSource = grid;
          GridView2.DataBind(); // here is the problem , the result get one value "last value saved in datatable " 
      }
 
Share this answer
 
Comments
shms_rony 27-Aug-13 4:42am    
That's good but it didn't work for me
the result is

//gridview1 // gridview2
pland countf

14/08/2013 0
18/08/2013

the result must be as following

pland countf

14/08/2013 2
18/08/2013 0

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



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900