Click here to Skip to main content
14,875,792 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Im designing a from with 31 textboxes in a column and the rows can increase to how many ever
like
<table>>
lt;tr>
<td colspan=31>
header
</td>
<tr>
<td><asp:TextBox id=txt1 ...</td>
</tr>
.
.
.
31

I want this to happen dynamically, when a user clicks and add row button
I tried using a literal control to include text
like


<table>>
lt;tr>
<td colspan=31>
header
</td>
<tr>
<td><asp:Literal ...</td>
</tr>

and

Literal1.Text += "" // html code for whole row

From what I understand you cannot include txtboxes in literal cause it can't have child controls so I used a PlaceHolder in place of a literal

on a button
addrow_click()<br />
{<br />
TextBox t1 = new TextBox();<br />
Literal l1 = new Literal();<br />
l1.Text="test";<br />
PlaceHolder1.Controls.Add(l1);<br />
PlaceHolder1.Controls.Add(l2);<br />
}<br />
<br />


This does add something to the form but not in the tabular format
and when I click the addrow button another time, the old controls (literal and textbox) are removed and a new one is added in place of that.
I want a new row to be added after the existing row can do this with one PlaceHolder ?
and How do I add a whole as shown above (with 31 textboxes) to the PlaceHolder in a tabular form?
Posted

What you have is an atrocious design. 31+ textboxes will be unwieldy and useless to end users, and will only get worse as you add more textboxes. Table layouts are slow to render and you are complicating it by adding more and more controls.

Given these limitations you need to add to add a row to the table, then cells to the row and controls to the cell. Not to a placeholder. This can be handled either client-side or server-side using an asp:table or marking the html table with runat=server to create a generic html control, or even databinding the table.
   
Comments
saud_a_k 22-Sep-10 14:41pm
   
I have to save this form to the databse with values for each day (hence 31 textboxes)
I thought of using a repeater control but the add row didnt work there , so do you suggest I use a server HTML table instead?
[no name] 22-Sep-10 15:10pm
   
There is no reason why a repeater would not work. Your implementation was obviously incorrect.
I believe you need to use repeaters.
but for you information dynamically added controls doesn't preserve their viewstate theirself. you are the one to maintain viewstate of each control.
   

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)




CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900