ASP.Net - how do I create a varying number of UserControls?

Discussion in 'ASP .Net' started by Clay Beatty, Nov 26, 2003.

  1. Clay Beatty

    Clay Beatty Guest

    OK, I am a .Net newbie... and I'm sure that if I spend the next two
    weeks pouring through MSDN articles, I will find the answer... But...
    I'm sure that this is done all the time, and so I'm sure the answer
    could be found here much more quickly :)

    I have a page, whose load event will execute a database query. Based
    on the number of rows returned from that query, I would like
    instantiate a new UserControl for each and every row. I would like to
    place those user controls into a dynamically generated HTML table, and
    also I would like to set the properties of each control based on the
    contents of the applicable row in the result set.

    Problem is, I don't have clue as to how to start this... I have
    searched these news groups, and found referneces to placeholder and to
    the LoadControl function... but I haven't seen a case close to the
    one I described above.

    The simplest code sample would be greatly appreciated.... Thank you in
    afvance :)

    Clay Beatty
    Clay Beatty, Nov 26, 2003
    #1
    1. Advertising

  2. Why dont you bind the resultset to an asp.net datagrid - it renders as a
    table and is very flexible, you can also set its output to use virtually any
    control you wish as the template for it which emans you should be abel to
    sue your user control. Tons of code examples around on databinding and
    templates.

    --
    Regards

    John Timney (Microsoft ASP.NET MVP)
    ----------------------------------------------
    <shameless_author_plug>
    Professional .NET for Java Developers with C#
    ISBN:1-861007-91-4
    Professional Windows Forms
    ISBN: 1861005547
    Professional JSP 2nd Edition
    ISBN: 1861004958
    Professional JSP
    ISBN: 1861003625
    Beginning JSP Web Development
    ISBN: 1861002092
    </shameless_author_plug>
    ----------------------------------------------

    "Clay Beatty" <> wrote in message
    news:...
    > OK, I am a .Net newbie... and I'm sure that if I spend the next two
    > weeks pouring through MSDN articles, I will find the answer... But...
    > I'm sure that this is done all the time, and so I'm sure the answer
    > could be found here much more quickly :)
    >
    > I have a page, whose load event will execute a database query. Based
    > on the number of rows returned from that query, I would like
    > instantiate a new UserControl for each and every row. I would like to
    > place those user controls into a dynamically generated HTML table, and
    > also I would like to set the properties of each control based on the
    > contents of the applicable row in the result set.
    >
    > Problem is, I don't have clue as to how to start this... I have
    > searched these news groups, and found referneces to placeholder and to
    > the LoadControl function... but I haven't seen a case close to the
    > one I described above.
    >
    > The simplest code sample would be greatly appreciated.... Thank you in
    > afvance :)
    >
    > Clay Beatty
    John Timney \(Microsoft MVP\), Nov 26, 2003
    #2
    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. Tom Kiefer
    Replies:
    6
    Views:
    585
    Corey O'Mara
    Feb 10, 2004
  2. Alan Silver
    Replies:
    9
    Views:
    912
    Alan Silver
    Jun 23, 2005
  3. Replies:
    12
    Views:
    482
  4. Ulf Meinhardt
    Replies:
    6
    Views:
    851
    Martin Gregorie
    Aug 25, 2009
  5. anthony
    Replies:
    5
    Views:
    107
    J├╝rgen Exner
    Dec 9, 2005
Loading...

Share This Page