add server controls to the templates for the DataList control.

Discussion in 'ASP .Net' started by Jon Paal, Mar 18, 2006.

  1. Jon   Paal

    Jon Paal Guest

    how do I load controls to the templates for the DataList control.

    <asp:datalist id="dl1" runat="server" >

    " how to load control(s) here ????"

    Jon Paal, Mar 18, 2006
    1. Advertisements

  2. You basically put a server control such as a Panel or a <div
    id="divOtherCtrls" runat="server"></div> (remember to declare the div or
    other HTML control if you use one) in the <ItemTemplate></ItemTemplate>
    tags. Then, to add the controls, use the Add() method of the Panel or div's
    Controls property. To do this, you would use code such as:


    This code must be placed inside either the ItemCreated or ItemDataBound
    events, otherwise the e object will not be available. Feel free to ask if
    you have any trouble.
    Nathan Sokalski, Mar 19, 2006
    1. Advertisements

  3. Jon   Paal

    Teemu Keiski Guest

    Teemu Keiski, Mar 19, 2006
  4. Jon   Paal

    Jon Paal Guest

    Although I appreciate your offer to help, I couldn't understand/implement either of the suggested solutions.

    Since I couldn't get the datalist to work, I found an alternate approach to organize the display of dynamic controls into a page.
    To keep it simple, I used a placeholder(ph1) in the html and I did this in the page_load code:

    ph1.Controls.Add (New LiteralControl("<table>"))
    For each oItem in arrMyControlList
    ph1.Controls.Add (New LiteralControl("<tr><td>"))
    ph1.Controls.Add( oItem.A)
    ph1.Controls.Add (New LiteralControl("</td><td>"))
    ph1.Controls.Add( oItem.B )
    ph1.Controls.Add (New LiteralControl("</td></tr>"))
    ph1.Controls.Add (New LiteralControl("</table>"))
    Jon Paal, Mar 19, 2006
    1. Advertisements

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.