Reputation: 15
i want to ask a question about dynamic table on asp.net c# i want to make a dynamic table but on this table i want to insert radiobutton on every table row and column. table create based on user input. if user input row 3 and column 3 system can display row length is 3 and column length is 3
input from user is
<asp:TextBox ID="rows" runat="server" MaxLength="20" Width="272px" AutoCompleteType="Disabled"></asp:TextBox>
<asp:TextBox ID="column" runat="server" MaxLength="20" Width="272px" AutoCompleteType="Disabled"></asp:TextBox>
<asp:Button ID="create" runat="server" Text="create table" CssClass="art-button" OnClick="create_Click" />
then the result is sistem display a table with row as long as user input on rows.textbox and column as long as column.textbox and on every rows and column has one radiobutton
anyone please help
Upvotes: 1
Views: 1980
Reputation: 446
Try this code.I think this is what you looking for.
protected void create_Click(object sender, EventArgs e)
{
Table dynamicTable = new Table();
TableRow Row;
TableCell Cell;
int rowno=int.Parse(rows.Text);
int cols=int.Parse(column.Text);
for (int row = 0; row < rowno; row++)
{
Row = new TableRow();
dynamicTable.Rows.Add(Row);
for (int col = 0; col < cols; col++)
{
Cell = new TableCell();
// adding radiobutton
RadioButton rad = new RadioButton();
rad.ID = "rad_" + col.ToString();
Cell.Controls.Add(rad);
Row.Cells.Add(Cell);
}
}
}
It will create dynamic table with radio button as user input.
Upvotes: 1