Click here to Skip to main content
15,885,882 members
Please Sign up or sign in to vote.
4.50/5 (2 votes)
See more:
I have created a table and I want to add row dynamically in this table.

<asp:Table ID="Table1" runat="server" Width="36px">
<asp:Table>


Code file:
protected void Button1_Click(object sender, EventArgs e)
    {
        TableRow row = new TableRow();
        TableCell cell1 = new TableCell();
        TableCell cell2 = new TableCell();
        TextBox txtt = new TextBox();
       
        txtt.ID = "txt";

        DropDownList dpn_phone = new DropDownList();
        dpn_phone.Items.Add("Home");
        dpn_phone.Items.Add("Work");
        dpn_phone.Items.Add("Mobile");
        dpn_phone.ID = "pho";

        cell1.Controls.Add(txtt);
        cell2.Controls.Add(dpn_phone);
        row.Cells.Add(cell1);
        row.Cells.Add(cell2);

        Table1.Rows.Add(row);
        ph.Controls.Add(t);
    }


But when any round trip is happening then Table1 rows are deleting
Posted
Updated 24-Jun-11 3:40am
v2
Comments
R. Giskard Reventlov 24-Jun-11 9:41am    
Have you preserved the new rows in ViewState prior to a post back so that any previously created rows can be added back to the table?
fjdiewornncalwe 24-Jun-11 11:02am    
You should put that in an answer because that is the likely cause of his data "going away"
R. Giskard Reventlov 24-Jun-11 12:06pm    
I though it more of a question but, hey ho, I always do as I'm told. :-)
Surendra Tarai 25-Jun-11 1:31am    
Hey ,who are you !

if u know answer then give nethier not . i can not do what u told ,right.if u do not know answer it is ok

1 solution

Have you preserved the new rows in ViewState prior to a post back so that any previously created rows can be added back to the table?

This[^] might help to get you started.
 
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