Solved

Need help on programmatically setting HeaderTemplate for DataList...

Posted on 2009-06-30
1
399 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

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

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…
Introduction Although it is an old technology, serial ports are still being used by many hardware manufacturers. If you develop applications in C#, Microsoft .NET framework has SerialPort class to communicate with the serial ports.  I needed to…
Nobody understands Phishing better than an anti-spam company. That’s why we are providing Phishing Awareness Training to our customers. According to a report by Verizon, only 3% of targeted users report malicious emails to management. With compan…

861 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