|
code
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
multiple itemtemplates datalistHi, 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. 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.NamingContainer).DataItem, "Text"); } void titleLabel_DataBinding(object sender, EventArgs e) { Label label = (Label)sender; label.Text = (string)DataBinder.Eval(((DataListItem)label.NamingContainer).DataItem, "Title"); } void selectButton_DataBinding(object sender, EventArgs e) { LinkButton button = (LinkButton)sender; DateTime date = (DateTime)DataBinder.Eval(((DataListItem)button.NamingContainer).DataItem, "Date"); try { button.Text = date.ToString(_control.Settings.DateFormat); } catch (FormatException) { button.Text = date.ToShortDateString(); } } }
Disable Button after click it
Panel Syntax Dynamically load webcontrol TypeConverter Question Dynamically show different web controls WebControl Click Event Not Firing ButtonColumn and EditCommandColumn don't work together as expected in DataGrid Dynamically changing LinkButton properties Clearing textbox controls after postback Hyperlink within a label |
|||||||||||||||||||||||