Link to home
Start Free TrialLog in
Avatar of netformx
netformx

asked on

load control dynamically in the table

Hi,

I have table that looks:
Label   textbox
Label   textbox

I want to load label and textbox dynamically.
I put 2 PlaceHolders :
<TR>
      <TD>
            <asp:PlaceHolder id="PlaceHolder_Labels" runat="server"></asp:PlaceHolder></TD>
      
      <TD>
            <asp:PlaceHolder id="PlaceHolder_Values" runat="server"></asp:PlaceHolder></TD>
</TR>


  but when I add to PlaceHolder.Controls it looks:
Label1Label2 textbox1textbox2

and I need:
Label1 textbox1
Label2 textbox2

How to achive that?
Avatar of orbulat
orbulat
Flag of Hong Kong image

u may try this, add Literal control to fix the alignment

Literal lit = new Literal();
lit.Text = "<br>";

PlaceHolder_Labels.Controls.Add(Label1);
PlaceHolder_Labels.Controls.Add(lit);
PlaceHolder_Labels.Controls.Add(Label2);

PlaceHolder_Values.Controls.Add(textbox1);
PlaceHolder_Values.Controls.Add(lit);
PlaceHolder_Values.Controls.Add(textbox2);
Avatar of GavinMannion
GavinMannion

Try adding a label between the two textboxes where the label has a value of <BR>.

Else a better way would be to create a small table and add the textboxes to the table rows and add the table to the placeholder.
Avatar of netformx

ASKER

with <BR> it does not look well (since text box is of 4 rows and label should be in the middle of it - when it's in table it looks OK.

can you write the simple example how to create a small table + then iterate on labels and values and fill values,
I can think of the follwoing:
add :
<TR>
<TD>
LABEL
</TD>
to PlaceHolder_Labels.Controls

and add
<TD>
textbox
</TD>
</TR>
to PlaceHolder_TextBoxes.Controls

iteration:
for(int i=0; i<PlaceHolder_Labels.Controls.Count; i++)
{
if (PlaceHolder_Labels.Controls[i] is Label)
   myTextBox = PlaceHolder_Vals.Controls[i-1] //i-1 becasue of table
 
}


but it's seems very clumsy to me, maybe you can suggest more elegant way?
ASKER CERTIFIED SOLUTION
Avatar of GavinMannion
GavinMannion

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
thanks, it worked great!