http://forums.asp.net/t/1162928.aspx/1
Re: how to find control from header template of a datalist?
Jan 04, 2010 07:28 AM | LINK
Instead of finding the control in the header template of datalist in page load event .you can put the code which you want to execute after finding the control inside a function and then call that function from the header template.Below is a example:->
<asp:DataList ID="dtlisFirstSubCategories" runat="server">
<HeaderTemplate>
<%#GetParentCategoryName() %>
</HeaderTemplate>
<ItemTemplate>
<asp:LinkButton ID="lbtnSubCategory" runat="server" CommandArgument='<%#Eval("ProductCategoryID")%>'
Text='<%#Eval("Name")%>' PostBackUrl='<%#"~/Category.aspx?parentCategoryID="+Eval("ProductCategoryID") %>'
OnClick="lbtnSubCategory_Click"> </asp:LinkButton>
</ItemTemplate>
</asp:DataList>
now in cs file you can put code as follows:->
public string GetParentCategoryName()
{
String parentCategoryName="";
//add logic here to get the category name
return parentCategoryName;
}
<asp:DataList ID="dtlisFirstSubCategories" runat="server">
<HeaderTemplate>
<%#GetParentCategoryName() %>
</HeaderTemplate>
<ItemTemplate>
<asp:LinkButton ID="lbtnSubCategory" runat="server" CommandArgument='<%#Eval("ProductCategoryID")%>'
Text='<%#Eval("Name")%>' PostBackUrl='<%#"~/Category.aspx?parentCategoryID="+Eval("ProductCategoryID") %>'
OnClick="lbtnSubCategory_Click"> </asp:LinkButton>
</ItemTemplate>
</asp:DataList>
now in cs file you can put code as follows:->
public string GetParentCategoryName()
{
String parentCategoryName="";
//add logic here to get the category name
return parentCategoryName;
}
No comments:
Post a Comment