DataList, Repeater,...?

  • Thread starter =?ISO-8859-1?Q?Andr=E9_Nobre?=
  • Start date
?

=?ISO-8859-1?Q?Andr=E9_Nobre?=

Hi all...

I need to put 20 textbox in an aspx, but I don't want to put it
manually. How can I code a Sub to do that? Something like a For. I tried
using a For and puting the asp:textbox code inside a asp:label. It
didn't worked. Can I use DataList ou Repeater with a fixed number os
repetitions, not based on DataSet or DataTable?

Thankz,
André
 
R

Roger Helliwell

Hi all...

I need to put 20 textbox in an aspx, but I don't want to put it
manually. How can I code a Sub to do that? Something like a For. I tried
using a For and puting the asp:textbox code inside a asp:label. It
didn't worked. Can I use DataList ou Repeater with a fixed number os
repetitions, not based on DataSet or DataTable?

Hi Andre,

If you want to stick with your 'for loop' strategy, you could put a
<asp:placeHolder> control on your page and in your code-behind, add
each new TextBox to the Controls collection of the placeholder.

TextBox tb = null;
for (int i=0; i < 20; i++)
{
tb = new TextBox();
// customize each textbox as you see fit
PlaceHolder1.Controls.Add(tb);
}

Hope that gets you start.

Roger
 
Y

Yunus Emre ALPÖZEN [MCAD.NET]

Using placeholder is a solution. But generally not a wanted one. Because you
would like to display something nearby textboxes.

My advice u to use a repeater. By this way you can easily separate your
design and code.

You can use any collection to bind it. no need to use a datatable or a
dataset. For instance, just use an arraylist. And fill arraylist with
indexes.

ArrayList al = new ArrayList();
for(int i=0;i<20;i++) al.Add();
repeater1.DataSource=al;
repeater1.DataBind();
 
P

Prodip Saha

Placeholder is the best solution. Placement of the TextBox can be controlled
by using another container object (HtmlTable). Just add the textboxes in the
table and add the table to the placeholder (beauty of Controls.Add !!).
Going further- onClick event handler can be added to the TextBox control as
soon as they are created(with uniqueid).

Repeater approach may run into name conflict (ID=??). You can change the ID
attribute during the binding event. It can be done but it would be too
complex.

Prodip
www.aspnet4you.com

Read my recent article on ASP.NET-
Friday! Trace Asp.Net Application User Information
 
?

=?ISO-8859-1?Q?Andr=E9_Nobre?=

For now I used the ArrayList solution, it was quite fast for me
(learning). I going to study PlaceHolder to know if it was the best
choice for that case.

Thanks for the answers,
André
 

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

No members online now.

Forum statistics

Threads
473,777
Messages
2,569,604
Members
45,227
Latest member
Daniella65

Latest Threads

Top