Solved

Need help on programmatically setting HeaderTemplate for DataList...

Posted on 2009-06-30
1
389 Views
Last Modified: 2013-11-05
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
Comment
Question by:WebAppDeveloper
1 Comment
 
LVL 9

Accepted Solution

by:
tetorvik earned 500 total points
ID: 24751517
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

Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

Join & Write a Comment

In order to hide the "ugly" records selectors (triangles) in the rowheaders, here are some suggestions. Microsoft doesn't have a direct method/property to do it. You can only hide the rowheader column. First solution, the easy way The first sol…
Summary: Persistence is the capability of an application to store the state of objects and recover it when necessary. This article compares the two common types of serialization in aspects of data access, readability, and runtime cost. A ready-to…
This video shows how to remove a single email address from the Outlook 2010 Auto Suggestion memory. NOTE: For Outlook 2016 and 2013 perform the exact same steps. Open a new email: Click the New email button in Outlook. Start typing the address: …
This tutorial demonstrates a quick way of adding group price to multiple Magento products.

743 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now