DataList Query

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




Responses

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

Up
0
Down
Lets say you have following DataList

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

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


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.

Regards,
Sheo Narayan
http://www.dotnetfunda.com

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

Login to post response