c# – How do you access one repeater’s control into another repeater’s OnItemCommand() method? – Education Career Blog

lets say I want to make a label of repeater1 visible in repater2’s ItemCommand() method..

e.Item.FindControl("rpt1Label").Visible=True;

is not working..how else do you do it ?

EDIT

changed that to repeater1.FindControl("rpt1Label").Visible=True;

This is throwing object reference null exception

,

inside the repeater (normal way to do it for a repeater):

Label thisLabel = (Label)e.item.findcontrol("rpt1Label");

if(thislabel != null 
{
   thislabel.visible = true;
}

if you have a 2nd repeater nested in your first repeater:

Repeater thisRepeater = (Repeater)e.Item.FindControl("repeaterName");
Label thisLabel = (Label)thisRepeater.findcontrol("rpt1Label"); 

if(thislabel != null  
{ 
   thislabel.visible = true; 
} 

Normally it should just be possible to acces the repeater1 from repeater2 by accessing:

(Label) thisLabel = (Label)this.repeater1.findcontrol("labelname");

Leave a Comment