473,320 Members | 2,004 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

adding linkbuttons at run time?

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,

Mar 31 '06 #1
2 1065
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)
{

}

Mar 31 '06 #2
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" <so*******@yahoo.com> wrote in message
news:11**********************@e56g2000cwe.googlegr 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,

Mar 31 '06 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: CodeRazor | last post by:
Hi, I am trying to dynamically create linkbuttons. They need an event handler, so i can respond to the user's click. I try to add the eventhandler on the fly, but when i click on the link, the...
6
by: Andrew Robinson | last post by:
I have a page that contains a number of link buttons that are used for making selections. I load my LinkButtons during the Page_PreInit event and they render fine but then I need to make a change...
1
by: jack | last post by:
Hi folks, I got a custom control, in which it's placed inside the UpdatePanel. The control contains some LinkButtons which post back to the same page. Actually, when these LinkButtons are clicked,...
8
by: Hamayun Khan | last post by:
Hi I have created linkbuttons dynamically using the below code Sub createlinkbutton(ByVal commandtext As String, ByVal Cmdarg As String, ByVal pane As Panel, ByVal count As Int32) Dim i =...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.