1

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

1 Answer 1

1

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.

Sign up to request clarification or add additional context in comments.

6 Comments

i must create table first or not, like <table id="tableContent" border="1" runat="server"></table>
i got what's your code mean and its done thanks, but where did i put the value or ID of radiobutton? what i supose to do if display of table has rows and column like excel(ex: A1,A2, etc)? thanks before
i am happy that it helps you.. For your next query::i am not getting what you are asking.can you be more clear?
when table create successfully then i choose one of radiobutton, what i supose to do if i want to got the value of radiobutton? because i want to insert the value of radiobutton to my database
if i want to do the same thing inside a js file, how should i Proceed?
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.