1

ボタンだけでなく、リピーター コントロールにも DropDownList があります。

ボタンを有効にしたい場合、DropDownListで有効なアイテムが選択されるまで、ボタンは無効になります。残念ながら、私はそれに到達できないようです。

次の方法でリピーターを見つけました: (.As() メソッドは (object as T) の拡張メソッドであり、キャストが簡単になります)

sender.As<Control>().NamingContainer.Parent.As<Repeater>()

ただし、FindControl(string name) 関数が何も返さないため、返された Repeater は役に立ちません。ウォッチ ウィンドウには何も表示されません。

では、リピーターの別のアイテムのイベント (この場合は DropDown_SelectedIndexChanged) から、リピーターの兄弟コントロール (この場合は ImageButton) を取得するにはどうすればよいでしょうか?

編集

やっと頑張りました

sender.As<ImageButton>().NamingContainer.As<RepeaterItem>().FindControl("ControlName")
4

1 に答える 1

5

私はあなたの質問に対する答えを持っていると思います:

1.-テストを実行するためのドロップダウンリストとボタンを備えたリピーターを作成します。

 <asp:Repeater ID="rp" runat="server">
   <ItemTemplate>
        <asp:DropDownList ID="DropDownList1" AutoPostBack="true" runat="server" OnSelectedIndexChanged="DropDownList1_SelectedIndexChanged">
        <asp:ListItem>1</asp:ListItem>
        <asp:ListItem>2</asp:ListItem>
        <asp:ListItem>3</asp:ListItem>
        <asp:ListItem>4</asp:ListItem>
        <asp:ListItem>5</asp:ListItem>
        <asp:ListItem>6</asp:ListItem>

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

リピーターをデータバインドします。

2.- メソッド 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;

        }

    }

それを行う方法は、その親であるコントロール、つまり RepeaterItem に尋ねることです。または、(最後に書いたように) NamingContainer を使用して、内部にあるコントロールについて尋ねることができます。

于 2008-11-27T10:00:15.567 に答える