Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > ASP .Net Web Controls > multiple itemtemplates datalist

Reply
Thread Tools

multiple itemtemplates datalist

 
 
krallabandi@gmail.com
Guest
Posts: n/a
 
      01-06-2006
Hi, Can a datalist supports multiple itemtemplates? I want to have 2
itemtemplates in a single datalist. In 1st template I will display the
data from one dataset and in another I will display data from 2nd
dataset.

Is it possible? any knowledge base article for this?

Thanks.

 
Reply With Quote
 
 
 
 
Wouter van Vugt
Guest
Posts: n/a
 
      01-10-2006
You could set the template programmatically to do this. The DataList
only supports one ItemTemplate by default. Here is an example which
also uses databinding usually found in a DataList template markup. The
AnnouncementsControl is some random control I've built a while ago.

Using two of these classes, you could achieve your goal.
With this sort of code, you can call something like

myDataList.ItemTemplate = new
AnnouncementsTemplate(myAnnouncementsControl)

Grtz,

Wouter van Vugt
Trainer - Info Support
http://blogs.infosupport.com/wouterv


class AnnouncementsTemplate : ITemplate
{
AnnouncementsControl _control = null;

public AnnouncementsTemplate(AnnouncementsControl control)
{
_control = control;
}

public void InstantiateIn(Control container)
{
if (_control.Settings.ShowMessageDate)
{
LinkButton selectButton = new LinkButton();
selectButton.CommandName = "Select";
selectButton.DataBinding += new
EventHandler(selectButton_DataBinding);
container.Controls.Add(selectButton);
container.Controls.Add(new LiteralControl("  "));
}
Label titleLabel = new Label();
titleLabel.DataBinding += new EventHandler(titleLabel_DataBinding);
container.Controls.Add(titleLabel);
container.Controls.Add(new LiteralControl("<BR/>"));

Label bodyLabel = new Label();
bodyLabel.DataBinding += new EventHandler(bodyLabel_DataBinding);
container.Controls.Add(bodyLabel);
container.Controls.Add(new LiteralControl("<BR/>"));
}

void bodyLabel_DataBinding(object sender, EventArgs e)
{
Label label = (Label)sender;
label.Text =
(string)DataBinder.Eval(((DataListItem)label.Namin gContainer).DataItem,
"Text");
}

void titleLabel_DataBinding(object sender, EventArgs e)
{
Label label = (Label)sender;
label.Text =
(string)DataBinder.Eval(((DataListItem)label.Namin gContainer).DataItem,
"Title");
}

void selectButton_DataBinding(object sender, EventArgs e)
{
LinkButton button = (LinkButton)sender;
DateTime date =
(DateTime)DataBinder.Eval(((DataListItem)button.Na mingContainer).DataItem,
"Date");
try
{
button.Text = date.ToString(_control.Settings.DateFormat);
}
catch (FormatException)
{
button.Text = date.ToShortDateString();
}
}
}

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Multiple ItemTemplates in one TemplateField JPabich ASP .Net 0 06-04-2007 02:10 PM
Nested DDL in GridView ItemTemplates bigbrorpi@gmail.com ASP .Net 2 04-05-2006 03:26 PM
Datagrid with textboxes on itemtemplates Luis Esteban Valencia ASP .Net 0 01-26-2005 02:15 PM
Setting up a datalist control - Item_DataBound for a datalist in a datalist Nevyn Twyll ASP .Net 8 09-09-2004 10:13 PM
Datallist with 2 different <itemtemplates> aaapaul ASP .Net 3 06-21-2004 06:30 AM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57