Click here to Skip to main content
15,886,518 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hello,

I am using nested datalist. in nested datalist i am using header template and footer template. i am binding 2 labels in footer templates.
now how to access this 2 labels value in header templates.

because when i click on header templates linkbutton that time i need this 2 labels value.

i will try this code (given below)
Int16 post_id = Convert.ToInt16(((Label)e.Item.FindControl("Label3")).Text);

It gives error like : Object reference not set to an instance of an object.



Thanks.
Shailesh prajapati.
Posted
Updated 28-Dec-10 18:57pm
v2
Comments
Brij 29-Dec-10 1:07am    
Did you try to debug the code?
e.Item.FindControl("Label3") must be returning null. Means not able to find?

As you are finding the control in your Footer, you need to add additional condition.

C#
if (e.ItemType == ListItemType.Footer)
{
   int post_id = Convert.ToInt16(((Label)e.Item.FindControl("Label3")).Text); 
}




Mark it as answer if it is really helpful.
 
Share this answer
 
Comments
shailesh125 29-Dec-10 1:47am    
Thnkyou very very much for replying.

but, i want to access footer control in header.

like this.
if(e.ItemType == ListItemType.Header)
{
access footer label.
}
Venkatesh Mookkan 29-Dec-10 1:51am    
I am not sure what is your business need to access Footer when you are at Header item.

In that case try the below,
yourDataList.Items[yourDataList.Items.Count-1].FindControl("Label3")

I am not sure, this is gonna work.
thatraja 29-Dec-10 2:24am    
@Venkatesh : Hi, I think they are put things like count, sum, total things in the footer so they want to get the things to other operations.
Venkatesh Mookkan 29-Dec-10 2:39am    
Even for that he can use a variable, keep adding it until the item is footer. It is a simple logic.
thatraja 29-Dec-10 7:10am    
but they chose that way :)
Off course You might getting NULL as Brij suggested while getting Label3 using FindControl.

If you're very sure on lable there, Then check proper spelling whether some character in upper or lower case in Label3.
 
Share this answer
 
Label id= (Label)DataList1.Items[i].FindControl("Label2");
 int post_id=Convert.ToInt32(id.Text.ToString());

use it .
 
Share this answer
 
v2
Comments
thatraja 29-Dec-10 2:22am    
Added code block

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900