User controls in DataList

Discussion in 'ASP .Net' started by Amil Hanish, Aug 14, 2006.

  1. Amil Hanish

    Amil Hanish Guest

    I want to create a bunch of like user controls and display them in a
    DataList.

    Does anyone have a GOOD example of how to do this?

    I thought I had it...I added the user control to my <ItemTemplate>, created
    an array of user controls in my code behind and set the DataSource and
    called DataBind. But, all the user controls are unitialized when the page
    is rendered.

    Amil
     
    Amil Hanish, Aug 14, 2006
    #1
    1. Advertising

  2. Amil Hanish

    Riki Guest

    Amil Hanish wrote:
    > I want to create a bunch of like user controls and display them in a
    > DataList.
    >
    > Does anyone have a GOOD example of how to do this?
    >
    > I thought I had it...I added the user control to my <ItemTemplate>,
    > created an array of user controls in my code behind and set the
    > DataSource and called DataBind. But, all the user controls are
    > unitialized when the page is rendered.
    >
    > Amil


    Just put the user control in the template like you would do with any other
    control (e.g. a textbox).
    Bind the properties of the user control that you need.

    The DataList will create the "array" of user controls automatically.

    The setup of the user control should be done by the user control itself as
    soon as its properties are assigned.
    Whether it is in a template, or just in a page by itself, should not make a
    difference.

    --
    Riki
     
    Riki, Aug 14, 2006
    #2
    1. Advertising

  3. Amil Hanish

    Amil Hanish Guest

    Ahh...I think I've got it. I was creating my own array, but so was
    asp.net...that's the reason all my objects were not initialized...they were
    asp.net's objects (not the ones I created).

    It's sort of a complex algorithm to set the user control properties. Can I
    call a protected method from the datalist <ItemTemplate>, passing it the
    asp.net object, and then let my method set the specific values?

    Thanks.

    Amil


    "Riki" <> wrote in message
    news:...
    > Amil Hanish wrote:
    >> I want to create a bunch of like user controls and display them in a
    >> DataList.
    >>
    >> Does anyone have a GOOD example of how to do this?
    >>
    >> I thought I had it...I added the user control to my <ItemTemplate>,
    >> created an array of user controls in my code behind and set the
    >> DataSource and called DataBind. But, all the user controls are
    >> unitialized when the page is rendered.
    >>
    >> Amil

    >
    > Just put the user control in the template like you would do with any other
    > control (e.g. a textbox).
    > Bind the properties of the user control that you need.
    >
    > The DataList will create the "array" of user controls automatically.
    >
    > The setup of the user control should be done by the user control itself as
    > soon as its properties are assigned.
    > Whether it is in a template, or just in a page by itself, should not make
    > a difference.
    >
    > --
    > Riki
    >
     
    Amil Hanish, Aug 14, 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. Nevyn Twyll
    Replies:
    8
    Views:
    1,876
  2. manu_srinivasa
    Replies:
    0
    Views:
    384
    manu_srinivasa
    Nov 24, 2004
  3. Roman
    Replies:
    2
    Views:
    640
    =?Utf-8?B?UHJha2FzaC5ORVQ=?=
    Jan 4, 2005
  4. Faizan Ahmed
    Replies:
    1
    Views:
    288
    John Saunders
    Jan 4, 2005
  5. Faizan Ahmed
    Replies:
    1
    Views:
    366
    John Saunders
    Jan 4, 2005
Loading...

Share This Page