How to add textbox to each and every cell in a table row and let user add multiple rows?

StackOverflow https://stackoverflow.com/questions/15542236

  •  29-03-2022
  •  | 
  •  

Domanda

Following is my markup code:

<asp:Table ID="tbldata"  runat="server" BorderWidth="2">
<asp:TableHeaderRow ID="tableheaderrow1" runat="server">
<asp:TableHeaderCell Width="80" runat="server">SNO</asp:TableHeaderCell>
<asp:TableHeaderCell Width="200" runat="server">Particulars</asp:TableHeaderCell>
<asp:TableHeaderCell Width="80" runat="server">Amount</asp:TableHeaderCell>
<asp:TableHeaderCell Width="120" runat="server">Tax</asp:TableHeaderCell>
<asp:TableHeaderCell Width="300" runat="server">OtherExpenditures</asp:TableHeaderCell>
<asp:TableHeaderCell Width="80" runat="server">NetAmount</asp:TableHeaderCell>
</asp:TableHeaderRow>
</asp:Table>

and following is my CS code

protected void txtCalendar_TextChanged(object sender, EventArgs e)
{
    TextBox t = new TextBox();
    TableRow rowNew = new TableRow(); // Creating a new table row
    for (int i = 0; i < 6; i++)
    {
        TableCell tcell = new TableCell();
        tcell.Controls.Add(t);         // add the textbox control at cell zero
        // or you can add it as
        rowNew.Controls.Add(tcell);
    }
    tbldata.Controls.Add(rowNew);
}

I want to add textbox to every cell in a table row so that the user may enter data there, but with the above code, textbox is only added to the last cell. What should I do to add textbox to each and every cell? There are 5 header columns as indicated by markup above. I want to add textbox to each and every column.How can I do it? Also I want to include a button named Add Row which when clicked lets user add rows. How can I do this as well?

È stato utile?

Soluzione

That is not a very easy requirement to satisfy.

Luckily Matt Dotson made a BulkEditGridView many years back.

You can download the latest code of this custom control from codeplex.

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top