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?
ASP.NET

Avatar of undefined
Last Comment
netformx
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
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

Blurred text
THIS SOLUTION IS ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
Avatar of netformx
netformx

ASKER

thanks, it worked great!
ASP.NET
ASP.NET

The successor to Active Server Pages, ASP.NET websites utilize the .NET framework to produce dynamic, data and content-driven web applications and services. ASP.NET code can be written using any .NET supported language. As of 2009, ASP.NET can also apply the Model-View-Controller (MVC) pattern to web applications

128K
Questions
--
Followers
--
Top Experts
Get a personalized solution from industry experts
Ask the experts
Read over 600 more reviews

TRUSTED BY

IBM logoIntel logoMicrosoft logoUbisoft logoSAP logo
Qualcomm logoCitrix Systems logoWorkday logoErnst & Young logo
High performer badgeUsers love us badge
LinkedIn logoFacebook logoX logoInstagram logoTikTok logoYouTube logo