Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 419
  • Last Modified:

Need help on programmatically setting HeaderTemplate for DataList...

Hi,

How do I programmatically set HeaderTemplate for DataList? For example, I want to programmatically create the "<HeaderTemplate>" tags for the DataList below (see code below) and set its value to "Product Information", e.g.,  "<HeaderTemplate><b>Product Information</b></HeaderTemplate>", during Page_Load.

Thanks a lot.

<asp:DataList 
            ID="dlProducts" CssClass="dataView" 
            Runat="server">
            <ItemTemplate>
            <h4><%#Eval("ProductName")%></h4>
            Description: <%#Eval("ProductDesc")%><br />
           Price: <%#Eval("ProductPrice")%>
            </ItemTemplate>
        </asp:DataList>

Open in new window

0
WebAppDeveloper
Asked:
WebAppDeveloper
1 Solution
 
tetorvikCommented:
you can create a user control (say YourUserControl.ascx) containing the html <b>Product Information</b>.
then you can load this control to your datalist header template dynamically with following (for example in aspx page_load before databinding):
            dlProducts.HeaderTemplate =  LoadTemplate("YourUserControl.ascx");

Hope this helps!
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Tackle projects and never again get stuck behind a technical roadblock.
Join Now