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:->
pkrishnan
Member
13 Points
84 Posts
how to find control from header template of a datalist?
Sep 26, 2007 07:42 AM|LINK
Hi,
I have a textbox in header template of a datalist.
From code behind i've to access these textbox from page_load event.
I tried with the following code.
DataList.Controls[0].FindControl(”myControl”)
But it have error.
how to solve it?
Krishna
kipo
All-Star
16475 Points
2811 Posts
Re: how to find control from header template of a datalist?
Sep 26, 2007 08:34 AM|LINK
You can access it from ItemDataBound event if you add this into DataList:
and put this in code-behind:pkrishnan
Member
13 Points
84 Posts
Re: how to find control from header template of a datalist?
Sep 26, 2007 09:12 AM|LINK
Hi kipo,
I'm not using any datalist event.
I've to get value from page load event.
Thanks
Krishna
kipo
All-Star
16475 Points
2811 Posts
Re: how to find control from header template of a datalist?
Sep 26, 2007 09:21 AM|LINK
Is there any special reason why you can't use DataList events?
GillouX
Contributor
2330 Points
606 Posts
Re: how to find control from header template of a datalist?
Sep 26, 2007 09:32 AM|LINK
the easiest option is to set a hidden field in javascript with and get it back in the page load
but as said before, why use the page load event to handle the datalist ?
pkrishnan
Member
13 Points
84 Posts
Re: how to find control from header template of a datalist?
Sep 26, 2007 10:03 AM|LINK
I
Because before databind i've to dynamically get a value from the user.
Krishna
kipo
All-Star
16475 Points
2811 Posts
Re: how to find control from header template of a datalist?
Sep 26, 2007 01:10 PM|LINK
I don't see why would that be a problem, but can you post your code?
ms.jatin_sah...
Member
6 Points
3 Posts
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;
}