FindControl which is inside of a Repeater control
-
linkButton lnkBtnRemove=(linkButton)Repeater1.items[0].findControl("lnkRemove");
lnkBtnRemove.visible=false;i used above code to make visible false of a link button i have placed in a repeater control.but it gives me the below error message. "Index was out of range.Must be non-negative and less than the size of the collection.Parameter name:index" i'm trying to use this in Page_load .pls help??
-
linkButton lnkBtnRemove=(linkButton)Repeater1.items[0].findControl("lnkRemove");
lnkBtnRemove.visible=false;i used above code to make visible false of a link button i have placed in a repeater control.but it gives me the below error message. "Index was out of range.Must be non-negative and less than the size of the collection.Parameter name:index" i'm trying to use this in Page_load .pls help??
Hi I tried the same piece of code and it worked for me. Make sure that you first bind the data to repeater control and then make it false. Naina
Naina
-
linkButton lnkBtnRemove=(linkButton)Repeater1.items[0].findControl("lnkRemove");
lnkBtnRemove.visible=false;i used above code to make visible false of a link button i have placed in a repeater control.but it gives me the below error message. "Index was out of range.Must be non-negative and less than the size of the collection.Parameter name:index" i'm trying to use this in Page_load .pls help??
Hii, You are getting error bcz your it unable to find th row at 0th index. So better use in the Repeater1_ItemDataBound event, also must check the condition: protected void Repeater1_ItemDataBound(object sender, RepeaterItemEventArgs e) { if (e.Item.ItemType == DataControlRowType.DataRow) { // your code.. LinkButton lnk = (LinkButton)e.Item.FindControl("control_id"); } } Or you can also go for this: This code will work inside/outside of anyevent foreach (RepeaterItemCollection item in Repeater1.Items) { LinkButton lnk = (LinkButton)item[0].FindControl("control_id"); } Now choice is yours which is more suitable for you but also mind in which scope you are using the code. Navin C.
-
Hii, You are getting error bcz your it unable to find th row at 0th index. So better use in the Repeater1_ItemDataBound event, also must check the condition: protected void Repeater1_ItemDataBound(object sender, RepeaterItemEventArgs e) { if (e.Item.ItemType == DataControlRowType.DataRow) { // your code.. LinkButton lnk = (LinkButton)e.Item.FindControl("control_id"); } } Or you can also go for this: This code will work inside/outside of anyevent foreach (RepeaterItemCollection item in Repeater1.Items) { LinkButton lnk = (LinkButton)item[0].FindControl("control_id"); } Now choice is yours which is more suitable for you but also mind in which scope you are using the code. Navin C.
thnks for the anzr.but didn't worked.it cant find any item index in the repeater control,i don't no why?help needed.. :( :( thnks in advance.
-
thnks for the anzr.but didn't worked.it cant find any item index in the repeater control,i don't no why?help needed.. :( :( thnks in advance.
Hii, Use this or mail me your scenario in which scope you want to use. Remmeber, before using this lines of code, you must bind your repeater control, otherwise it will not work as the control has no values. Hope this will work: foreach (RepeaterItem item in Repeater1.Items) { Label lbl = (Label)item.FindControl("lblName"); // Use any othe asp control that you want instead of 'Label'. if (lbl != null) { lbl.Text="I cached you!"; } } Or, for "DataBound" event of repeater you can use as:- protected void Repeater1_ItemDataBound(object sender, RepeaterItemEventArgs e) { if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem) { Label lbl = (Label)e.Item.FindControl("lblID"); if(lbl!=null) { // Do your code with found control; } } } Regards, Navin C. E-mail: navin2k6@gmail.com :)
modified on Tuesday, December 15, 2009 5:25 AM