Click here to Skip to main content
15,937,779 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have a grid view and i populate this grid view by data table,
but after some time i want to add new data on the existing grid view
how i add new data on the grid view from the datatable without disturbing the old state of gridview
please help me
thanks in advance
Posted
Comments
RDBurmon 6-Jan-12 6:05am    
What will be your event to load this data in an interval

1 solution

Just store your datatable is Session variable and add new row to datatable and give it as datasource to your gridview.

DataTable dt = null;
try
{
    if (Session["dtItems"] != null)
    {
        dt = (DataTable)Session["dtItems"];
    }
    else
    {
        dt = new DataTable();
        dt.Columns.Add("Quantity");
        dt.Columns.Add("Rate_Unit");
        dt.Columns.Add("Amount");
    }
    DataRow dataRow;
    dataRow = dt.NewRow();
    dataRow["Quantity"] = TextBox1.Text;
    dataRow["Rate_Unit"] = TextBox2.Text;
    dataRow["Amount"] = TextBox3.Text;
    dt.Rows.Add(dataRow);
    dt.AcceptChanges();
    Session["dtItems"] = dt;
    GridView1.DataSource = dt.DefaultView;
    GridView1.DataBind();
}
catch (Exception ex)
{
}
 
Share this answer
 
v3
Comments
Sridhar Patnayak 6-Jan-12 6:17am    
Good 5+
Prince Antony G 6-Jan-12 6:31am    
my 5+
Supriya Srivastav 6-Jan-12 6:48am    
Thanks
Rajesh Anuhya 6-Jan-12 7:58am    
Good answer Supriya , have my +5
Supriya Srivastav 7-Jan-12 0:54am    
Thanks Rajesh...

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