Hey guys. how do i create a loop so i can create a number of asp linkbutton?

            for (i = 0; i < filenames.Length; i++)

i have a loop the i want to generate linkbutton on my website, but i want it inside a table?

Who is Participating?
Pratima PharandeCommented:
See this for simple solution in Table

Add one Panel control in Aspx page like this
                  <asp:Panel id="Panel1"  runat="server">Panel</asp:Panel>

then in code behind linkbuttons like this

      Table table = new Table();
                  for (int i=0; i<10; i++)
                              LinkButton lbt = new LinkButton();
                        TableCell cell = new TableCell();
                        TableRow row = new TableRow();
                        lbt.Text = i.ToString();


                  Panel1.Visible = true;
John ClaesSenior .Net Consultant & Technical AnalistCommented:
You can generate it using a repeater.

A repeater will create it's inside for every Element you give it

what do you need to do?

Html side

set everything you want to repeat for every File inside the <asp:repeater> tag
In your example you must add the LinkButton

Code side
Create the OnDataBound method for the repeater
for the given e.Item as filename you set the linkbutton with the data.
(know the first time you come accros the e.item can be null just leave the method

In the onLoad you can set your list of filenames as DataSet for the repeater and call the DataBound method.

What will happen?

The list is databound to the repeater and the repeater is called to be DataBound.
On that moment the Code will send every item one by one through the onDataBound method
there you'll set the inner Linkbox

hope to be clear and helpfull.
JCWEBHOSTAuthor Commented:
do you have some code please so i can follow?
John ClaesSenior .Net Consultant & Technical AnalistCommented:
I'll give you some Urls

Gives a simple example of using the repeater with auto binding

using the repeater with ItemDataBound method

uisng the repeater without ItemDataBoudn method but using Server-Side coding within the Html

hope to have helped
Poor beggar
JCWEBHOSTAuthor Commented:
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.