How to create a table of TextBox

A

ad

I want to creat a 3x2 tables, there a TextBox in each cells.
How can I do it programlly ?
 
G

Guest

Lets say that you already have <asp:Table id="[TABLEID]"> on your page.

Sample how to add 1 row to table.
It would be smarter to use loop, but I leave that to you. :)

//Create new TableRow
TableRow row = new TableRow();
//Create 3 cells
TableCell cell1 = new TableCell();
TableCell cell2 = new TableCell();
TableCell cell3 = new TableCell();

//Create textboxes
TextBox box1 = new TextBox();
box1.ID = "box1";
TextBox box2 = new TextBox();
box1.ID = "box2";
TextBox box3 = new TextBox();
box1.ID = "box3";

//Add Textboxes to cells
cell1.Controls.Add(box1);
cell2.Controls.Add(box2);
cell3.Controls.Add(box3);

//Add created cells to table row
row.Cells.Add(cell1);
row.Cells.Add(cell2);
row.Cells.Add(cell3);

[TABLEID].Rows.Add(row);
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
474,434
Messages
2,571,691
Members
48,796
Latest member
Greg L.

Latest Threads

Top