In a master page
I am trying to create a dynamic table with 4 columns for a table row.
Actual my requirement is I have text box in which I will give a number basing on that number input it should create 4 column's in a row
ex: in my text box i/p is 5 then table should created in the below format
| Label1 | TetBox1 | Label2 | TextBox2 |
| Label3 | TextBox3 | Label4 | TextBox4 |
| Label5 | TextBox5 |
in this first column Level1 and textbox1 in 2nd column in the same way third column and fourth column's level2 and textbox2
in the above mentioned format my dynamic table should be created.
I have tried but recieving an error. Help is needed ASAP, As I stuck with this functionality

theLizardRank #1,079 · 1.8K reputationPosted Mar 3, 2016, 11:53 AM EST
{
int boxes=0, rows = 0, i=0, t=1, perrow = 0, k=0;
decimal j = 0;
int.TryParse(TextBox2.Text, out perrow);
int.TryParse(TextBox1.Text, out boxes);
string s = "
j = boxes;
if ( j % perrow != 0)
{
rows = (int)j/perrow + 1;
}
else
rows = (int)j / perrow;
for (i = 0; i < rows; i++)
{
s += "
for (k = 0; k < perrow; k++)
{
s = AddRow(s, t);
t++;
boxes--;
if (boxes == 0)
break;
}
if (k % perrow == 0)
s += "
}
s += "
TableDiv.InnerHtml = s;
}
private string AddRow(string s, int t)
{
s += "
s += "
return (s);
}
.auto-style1 {
width: 139px;
}
Phani KumarRank #2,870 · 500 reputationPosted Mar 3, 2016, 6:40 PM EST
Phani KumarRank #2,870 · 500 reputationPosted Mar 3, 2016, 6:46 PM EST
Phani KumarRank #2,870 · 500 reputationPosted Mar 3, 2016, 6:55 PM EST
ali tuncerRank #1,499 · 1.1K reputationPosted Mar 3, 2016, 7:25 PM EST
What does this line return? is it null? Probably this part has problem..
Table table = // new Table();
Amit KumarRank #459 · 5.4K reputationPosted Mar 3, 2016, 7:34 PM EST
Phani KumarRank #2,870 · 500 reputationPosted Mar 3, 2016, 8:00 PM EST
ali tuncerRank #1,499 · 1.1K reputationPosted Mar 3, 2016, 8:07 PM EST
Hi Phani,
That's the problem, you are trying to add rows to a table with id "tabletxtRoundNumber" in your page but it doesn't exist. You need to fix that part..you should look for a table id that exist in the page..
Phani KumarRank #2,870 · 500 reputationPosted Mar 3, 2016, 8:10 PM EST
Phani KumarRank #2,870 · 500 reputationPosted Mar 3, 2016, 8:17 PM EST
ali tuncerRank #1,499 · 1.1K reputationPosted Mar 3, 2016, 8:57 PM EST
Hi Phani,
Phani KumarRank #2,870 · 500 reputationPosted Mar 3, 2016, 9:03 PM EST
ali tuncerRank #1,499 · 1.1K reputationPosted Mar 3, 2016, 9:13 PM EST
could be related to css, or you might be creating them in a wrong place(could be wrong div,table,td..), if functionality is working, that part should be easier!
Phani KumarRank #2,870 · 500 reputationPosted Mar 3, 2016, 9:27 PM EST
ali tuncerRank #1,499 · 1.1K reputationPosted Mar 3, 2016, 9:46 PM EST
Now you are creating a table with id "tabletxtRoundNumber" in server side, with this line:
Answer a question in the forums and earn +20 SHARP for every answer.
See unanswered questionsTop experts