,
Share with your friends 

Dynamic Templates in ASP.NET for DataList Controls

4 ratings Views 320 
Author: Hefin (Hefin Dsouza)  View Profile |  View other solutions by this author

Question / Problem


I have a DataList control on a ASP.NET page and I need to Customise the Templates Depending on a Data Comming From a DataBase. Using The <HeaderTemplate>Some Thing Here</HeaderTemplate> in the ASPX page will not help me because The Data is retrived only in the <ItemTemplate> What will I Do?

Solution

The Code Below Will Allow you to Create a Object of TemplateBuilder Class.
The TemplateBuilder Class Can be used to Create Runtime Templates for the DataList control.
The TemplateBuilder class has a Method AppendLiteralString() which accepts string format and you can Type the HTML tags that you want in the Header

Dim ht As New System.Web.UI.TemplateBuilder

Can display any content
ht.AppendLiteralString("Any Content You Want to Display")

You can also Display Values from DataSets
ht.AppendLiteralString(qst.Rows(0)(1))

Setting the Template object with the DataList
The DataList Has Properties for
HeaderTemplate
FooterTemplate
ItemTemplate
all these templates can be set using these Properties

DataList1.HeaderTemplate = ht
DataList1.FooterTemplate = ht
DataList1.ItemTemplate = ht

Hope this Solution comes handy
 
Regards

Applies to

Asp.Net 2.0

Rank It

Login to rank it

Report


Advertisement