Wrox Programmer Forums
Go Back   Wrox Programmer Forums > ASP.NET and ASP > ASP.NET 2.0 > ASP.NET 2.0 Basics
|
ASP.NET 2.0 Basics If you are new to ASP or ASP.NET programming with version 2.0, this is the forum to begin asking questions. Please also see the Visual Web Developer 2005 forum.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the ASP.NET 2.0 Basics section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old September 26th, 2006, 02:14 PM
Registered User
 
Join Date: Aug 2006
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
Default keep adding table rows on button click

I put a table control on the aspx page like this:

     <asp:Table ID="Table1" runat="server" GridLines="Both" HorizontalAlign="Left" Width="80%">
        <asp:TableHeaderRow ID="TableHeaderRow1" runat="server">
            <asp:TableHeaderCell ID="TableHeaderCell2" Text="Trade" runat="server"></asp:TableHeaderCell>
            <asp:TableHeaderCell ID="TableHeaderCell3" Text="Hourly Rate" runat="server"></asp:TableHeaderCell>
            <asp:TableHeaderCell ID="TableHeaderCell4" Text="License" runat="server"></asp:TableHeaderCell>
        </asp:TableHeaderRow>

 </asp:Table>

Now I want to keep adding a new row to this table every time I click the button "Add New Row". The code behind is like this:

    protected void btnAddNewRow_Click(object sender, EventArgs e)
    {
        int i;
        TableCell[] arrayofTableRowCells = new TableCell[3];
        TableRow myTableRow = new TableRow();

        for (i = 0; i < 3; i++)
        {
            TableCell myTableCell = new TableCell();
            TableCell cell = new TableCell();
            TextBox myTextBox = new TextBox();
            myTableCell.Controls.Add(myTextBox);
            arrayofTableRowCells[i] = myTableCell;
        }

        TableCellCollection myTableCellCol = myTableRow.Cells;

        myTableCellCol.AddRange(arrayofTableRowCells);


        Table1.Rows.Add(myTableRow);
        Response.Write(Table1.Rows.Count.ToString());
    }


But it add only one row when the button is first clicked. Please help if you know it. Appreciated!!







Similar Threads
Thread Thread Starter Forum Replies Last Post
Button Click ~Bean~ ASP.NET 1.0 and 1.1 Basics 2 September 27th, 2005 09:32 AM
page take time to load after adding rows in table avanishp General .NET 5 June 21st, 2005 02:32 PM
Login Click Button mrideout BOOK: Beginning ASP.NET 1.0 6 August 12th, 2004 10:11 AM
Adding rows to a table in ASP.NET codebehind GilletteCat ASP.NET 1.0 and 1.1 Professional 2 August 3rd, 2004 02:56 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.