Retrieving sibling control from Repeater on event

I have a DropDownList on a repeater control, as well as a button.

The button is disabled until a valid item is selected on the DropDownList, when I want to enable the button. Unfortunately I can't seem to get to it.

Found the repeater by: (.As() method is an extension method for (object as T), just makes casting easier)


However the Repeater I get back doesn't help me as the FindControl(string name) function isn't returning anything - and shows nothing useful in the watch window.

So, how can I get a sibling control (an ImageButton in this case) on a repeater from an event of another item on the repeater (DropDown_SelectedIndexChanged in this case)?


I finally worked out


-------------Problems Reply------------

I think i have the answer for your question:

1.-I create a repeater with the dropdownlist and button to do the tests:

<asp:Repeater ID="rp" runat="server">
<asp:DropDownList ID="DropDownList1" AutoPostBack="true" runat="server" OnSelectedIndexChanged="DropDownList1_SelectedIndexChanged">

<asp:ImageButton ID="Button1" runat="server" Enabled="False" />

I databind the repeater.

2.-I create the method DropDownList1_SelectedIndexChanged:

protected void DropDownList1_SelectedIndexChanged(object sender, EventArgs e)
DropDownList control = (DropDownList)sender;

RepeaterItem rpItem = control.NamingContainer as RepeaterItem;
if (rpItem != null)
ImageButton btn = ((ImageButton)rpItem.FindControl("Button1"));
btn.Enabled = true;



The way to do it is to ask to the control, who is its Parent, that's to say, the RepeaterItem, or you can use NamingContainer (as I have written finally) and there you can ask about any control that is inside.

Category:c# Views:0 Time:2008-11-27
Tags: c# repeater

Related post

Copyright (C), All Rights Reserved.

processed in 0.612 (s). 11 q(s)