Solved

Need help on programmatically setting HeaderTemplate for DataList...

Posted on 2009-06-30
1
403 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

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

Suggested Solutions

Title # Comments Views Activity
need to convert function to c# 5 55
How can I do Unit Testing with Session ? 1 41
Selenium and Xpath 4 68
Visual Studio 2015 auto inserted code 12 88
Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
Suggested Courses

738 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