Click here to Skip to main content
15,912,205 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have a gridview in which I add a new row dynamically. I create a datatable and add it. When i bind data source to the gridview the prvious one gets replaced.

I want it to get appended.

how can i do it??

I have done this: (grid1 is a arraylist which is global)
C#
protected void Button4_Click(object sender, EventArgs e)
    {
        DataSet ds2 = (DataSet)Session["forgrid2"];
        DataRow dr = ds2.Tables[0].NewRow();
        ds2.Tables[0].Rows.Add(dr);
        
        dr[0] = TextBox9.Text;
        dr[1] = DropDownList1.SelectedItem.Text;
        dr[2] = TextBox11.Text;
        dr[3] = TextBox12.Text;
        dr[4] = TextBox13.Text;
        dr[5] = DatePicker3.SelectedDate.ToString();
               
        grid1.Add(ds2);
        foreach (DataSet ds in grid1)
        {
             GridView3.DataSource = ds;
             GridView3.DataBind();
         }
Posted
Updated 25-Feb-10 2:23am
v2

1 solution

What are you doing. You are creating a new DataSet rather than adding to the existing one.

First of all dont put Dataset into session. It is very bad practice. Rather populate the datagrid on demand.

So only doing
gridView3.DataSource = ds2;
gridView3.DataBind();


will be fine for you. No need to use For loop.

Also I recommend you to read some basic books.:cool:
 
Share this answer
 

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