adding linkbuttons at run time?

Discussion in 'ASP .Net' started by bazzer, Mar 31, 2006.

  1. bazzer

    bazzer Guest

    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,
     
    bazzer, Mar 31, 2006
    #1
    1. Advertising

  2. bazzer

    Jason Hales Guest

    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)
    {

    }
     
    Jason Hales, Mar 31, 2006
    #2
    1. Advertising

  3. 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" <> wrote in message
    news:...
    > 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,
    >
     
    S. Justin Gengo, Mar 31, 2006
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Vidar Petursson

    Re: LinkButtons and MouseOver

    Vidar Petursson, Jul 8, 2003, in forum: ASP .Net
    Replies:
    1
    Views:
    1,324
    sramruttun
    Jul 9, 2003
  2. Rick Glos
    Replies:
    0
    Views:
    659
    Rick Glos
    Jul 8, 2003
  3. Lucas Tam

    LoadPostData and LinkButtons

    Lucas Tam, Aug 18, 2003, in forum: ASP .Net
    Replies:
    0
    Views:
    345
    Lucas Tam
    Aug 18, 2003
  4. flamesrock
    Replies:
    8
    Views:
    557
    Hendrik van Rooyen
    Nov 24, 2006
  5. Pierre Yves
    Replies:
    2
    Views:
    526
    Pierre Yves
    Jan 10, 2008
Loading...

Share This Page