troubleshooting Question

Add New Rows to an existing ASP.Net Table

Avatar of kishan66
kishan66Flag for United States of America asked on
5 Comments1 Solution331 ViewsLast Modified:
Using (ASP Button or HyperLink)  onClick -> Add New Rows to an existing ASP table

I have create a table on button click (pls see code under code section).

Now, when ever user clicks on "Add More" , 4 Rows have to be appended to the existing table.

pls suggest me using javascript or itself 2.0,

ASPX code
    Rows: <asp:TextBox ID="txtRows" runat="server" Width="30px"> </asp:TextBox> <br />
    Cols: &nbsp;<asp:TextBox ID="txtCols" runat="server" Width="30px"></asp:TextBox>
     <asp:Button ID="btnGenerate" OnClick="btnGenerate_Click" runat="server" Text="Generate" />&nbsp;<br /> <br />
     <asp:Button ID="btnMoreRows" OnClick="btnMoreRows_Click" runat="server" Text="Add More" />&nbsp;<br /> <br />
	<asp:PlaceHolder ID="PlaceHolder1" runat="server"></asp:PlaceHolder>  

ASPX.CS code
ASP-Table Creation Function:
protected void btnGenerate_Click(object sender, EventArgs e)
 private void CreateDynamicTable()
    // Fetch the number of Rows and Columns for the table 
    // using the properties
    int tblRows = 4;
    int tblCols = 4;
    // Create a Table and set its properties 
    //tb1 = new Table();
    // Add the table to the placeholder control
    // Now iterate through the table and add your controls 
    for (int i = 0; i < tblRows; i++)
        TableRow tr = new TableRow();
        for (int j = 0; j < tblCols; j++)
            TableCell tc = new TableCell();
            TextBox txtBox = new TextBox();
            txtBox.Text = "RowNo:" + i + " " + "ColumnNo:" + " " + j;
            // Add the control to the TableCell
            // Add the TableCell to the TableRow
        // Add the TableRow to the Table

Open in new window

Alfred A.

Our community of experts have been thoroughly vetted for their expertise and industry experience.

Join our community to see this answer!
Unlock 1 Answer and 5 Comments.
Start Free Trial
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 5 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros