Click here to Skip to main content
15,888,065 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi all
Please help me

my following code should return the following result


VB
//gridview1             //gidview2
pland                   countf

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



but the result is the last record saved in " grid" datatable as following


VB
//gridview1             //gidview2
14/08/2013                 0
18/08/2013



This is my code

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"
         foreach (DataRow row in dt.Rows)
        {
       
      DataTable grid = new DataTable();
       
       
            inf.plandat = DateTime.Parse(row[0].ToString()); 
            grid = inf.gridshowfor();// this method take the date and get result

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

                
         }
Posted
Updated 28-Aug-13 22:52pm
v2

1 solution

Use Below Code :

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"
            var mainGrid = new DataTable();
            mainGrid.Columns.Add("Count");
            foreach (DataRow row in dt.Rows)
            {

                DataTable grid = new DataTable();


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

                foreach (DataRow dr in grid.Rows)
                {
                    if (dr != null && dr[0] != null)
                    {
                        var mainRow = mainGrid.NewRow();
                        mainRow["Count"] = dr[0];
                        mainGrid.Rows.Add(mainRow);
                    }
                }

                GridView2.DataSource = mainGrid;
                GridView2.DataBind(); // here is the problem , the result get only last record saved in datatable " 
            }
        }
 
Share this answer
 
v4
Comments
shms_rony 29-Aug-13 6:40am    
Yesssssssssssss It's worked
Thank you very very much :)

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