Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > adding linkbuttons at run time?

Reply
Thread Tools

adding linkbuttons at run time?

 
 
bazzer
Guest
Posts: n/a
 
      03-31-2006
hey,
i have an ASP.NET webform linking to a microsoft access database. at
runtime, i need the application to add x linkbuttons to a panel. x will
be the number of entries under a certain field in one of the tables
from the database, which can vary each time.

i just cant get my mind around how to go about doing this. could anyone
point me in the right direction or even just explain to me what i need
to do?

thanks,

 
Reply With Quote
 
 
 
 
Jason Hales
Guest
Posts: n/a
 
      03-31-2006
Hi Bazzar, it's pretty straight forward. Just create some LinkButtons
inside your Page_Load event and add these to the Panel's Controls
collection.

You must remember to add them even if it's a page PostBack otherwise
the Command events won't get fired when you click an item.

I've used the CommandArgument so set an ID as you'll need to know
which one was fired and they all go to the same event handler
button_Command:

private void Page_Load(object sender, System.EventArgs e)
{
int numLinks = 10;
for(int i = 0; i < numLinks; i++)
{
LinkButton button = new LinkButton();
button.Command += new CommandEventHandler(button_Command);
button.CommandArgument = i.ToString();
button.Text = "Entry " + i;
Panel1.Controls.Add(button);
Panel1.Controls.Add(new LiteralControl("<br/>"));
}
}

private void button_Command(object sender, CommandEventArgs e)
{

}

 
Reply With Quote
 
 
 
 
S. Justin Gengo
Guest
Posts: n/a
 
      03-31-2006
Bazzer,

I have a few examples of loading up controls dynamically on my website:
http://www.aboutfortunate.com?page=codelibrary

Use the search box there to search for dynamic controls and take a look at
the examples. If you have any questions after that feel free to email me.

Regards,

--
S. Justin Gengo
Web Developer / Programmer

Free code library:
http://www.aboutfortunate.com

"Out of chaos comes order."
Nietzsche


"bazzer" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed) oups.com...
> hey,
> i have an ASP.NET webform linking to a microsoft access database. at
> runtime, i need the application to add x linkbuttons to a panel. x will
> be the number of entries under a certain field in one of the tables
> from the database, which can vary each time.
>
> i just cant get my mind around how to go about doing this. could anyone
> point me in the right direction or even just explain to me what i need
> to do?
>
> thanks,
>



 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Re: Multiple LinkButtons with independent ValidationControls? Cowboy ASP .Net 1 05-27-2004 01:52 AM
Linkbuttons not working Stefan Landgraf ASP .Net 0 12-11-2003 01:18 PM
LoadPostData and LinkButtons Lucas Tam ASP .Net 0 08-18-2003 12:57 PM
Re: LinkButtons and MouseOver Vidar Petursson ASP .Net 1 07-09-2003 07:10 AM
Re: Dynamic Table with Dynamic LinkButtons Rick Glos ASP .Net 0 07-08-2003 01:09 PM



Advertisments