DataList Query

Posted by Raju under ASP.NET on 5/1/2008 | Views : 2025 | Status : [Member] | Replies : 1
How to accss footer template (containing some controls) of datalist programmatically in ASP.Net 2.0 ?


Posted by: SheoNarayan on: 5/1/2008 [Administrator] HonoraryPlatinum

Lets say you have following DataList

<asp:DataList runat="Server" id="DataList1" OnItemCreated="DataList1_ItemCreated">

<%# Eval("Name") %>
<asp:CheckBox ID="chk1" runat="Server" />

You will have to write following method (This method will fire in ItemCreated event of the DataList) to access the footer control.

protected void DataList1_ItemCreated(object sender, DataListItemEventArgs e)

if (e.Item.ItemType == ListItemType.Footer)
CheckBox chk = (CheckBox)e.Item.FindControl("chk1");
chk.Checked = true;

Note the e.Item.ItemType == ListItemType.Footer. If you want to work with Header you will have to select Header from ListItemType enumerator.

Sheo Narayan

Raju, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response