linkbutton

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?

JCWEBHOSTAsked:
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();

                        cell.Controls.Add(lbt);
                        row.Cells.Add(cell);
                        table.Rows.Add(row);

                  }
                  Panel1.Controls.Add(table);
                  Panel1.Visible = true;
0
 
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.
0
 
JCWEBHOSTAuthor Commented:
do you have some code please so i can follow?
0
 
John ClaesSenior .Net Consultant & Technical AnalistCommented:
I'll give you some Urls

Gives a simple example of using the repeater with auto binding
http://www.w3schools.com/ASPNET/aspnet_repeater.asp
http://blogs.sitepoint.com/asp-net-repeater-control/


using the repeater with ItemDataBound method
http://support.microsoft.com/kb/307860

uisng the repeater without ItemDataBoudn method but using Server-Side coding within the Html
http://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.repeater.itemdatabound.aspx

hope to have helped
Poor beggar
0
 
JCWEBHOSTAuthor Commented:
thanks
0
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.