2

TelerikRadComboBoxを含むリピーターがあります。

<asp:Repeater ID="rpt" runat="server">
    <ItemTemplate>
        <telerik:RadComboBox ID="rcb" runat="server" EnableLoadOnDemand="true"  
             AllowCustomText="true" ItemRequestTimeout="1000"
             NumberOfItems="10" MarkFirstMatch="false">
        </telerik:RadComboBox>
    </ItemTemplate>
</asp:Repeater>

リピーターのItemDataBoundイベントで、次のようにItemsRequestedイベントを接続しています。

private void rpt_ItemDataBound(object sender, RepeaterItemEventArgs e) {
    RadComboBox rcb = (RadComboBox)e.Item.FindControl("rcb");
    rcb.ItemsRequested += rcb_ItemsRequested;
}
private void rcb_ItemsRequested(object o, RadComboBoxItemsRequestedEventArgs e) {
    // Database call to load items occurs here.
    // As configured, this method is never called.
}

現在、サーバー側のrcb_ItemsRequestedメソッドが呼び出されることはありません。ItemDataBoundでItemsRequestedイベントを配線するのは問題があると思いますが、問題は他の場所にある可能性があります。

リピーター内でTelerikRadComboBoxを適切に使用する方法に関するアイデアはありますか?

4

1 に答える 1

1

イベントハンドラーの配線を動的に追加するのではなく、マークアップに入れてみましたか?

また、おそらくご存知でしょうが、念のために、ItemsRequestedは特定の条件下でのみ発生するイベントです。ドキュメントを引用するには:

The ItemsRequested event occurs when the EnabledLoadOnDemand property is True and the user types text into the input field or clicks on the drop-down toggle image when the list is empty.-リファレンス

あなたのシナリオは上記と一致しますか?

編集

私はいくつかのコードをテストしました。次の動作(ItemsRequestedイベントはすべてのComboBoxに対して発生し、3つのテスト項目をその場でドロップダウンに追加します。):

マークアップ:

<form id="form1" runat="server">
    <asp:ScriptManager ID="ScriptManager1" runat="server" />

    <asp:Repeater ID="rpt" runat="server" OnItemDataBound="rpt_ItemDataBound">
        <ItemTemplate>
            <br />
            <telerik:RadComboBox ID="rcb" runat="server" EnableLoadOnDemand="true" AllowCustomText="true"
            ItemRequestTimeout="1000" NumberOfItems="10" MarkFirstMatch="false" />
        </ItemTemplate>
    </asp:Repeater>
</form>

背後にあるコード:

protected void Page_Load(object sender, EventArgs e)
{
    List<string> data = new List<string>();
    data.Add("Item 1");
    data.Add("Item 2");

    //add some items to the repeater to force it to bind and repeat..
    rpt.DataSource = data;
    rpt.DataBind();
}

protected void rpt_ItemDataBound(object sender, RepeaterItemEventArgs e)
{
    //wire the event
    RadComboBox rcb = (RadComboBox)e.Item.FindControl("rcb");
    rcb.ItemsRequested += rcb_ItemsRequested;
}

protected void rcb_ItemsRequested(object sender, RadComboBoxItemsRequestedEventArgs e)
{
    //add the items when requested.
    (sender as RadComboBox).Items.Add(new RadComboBoxItem("Item1", "1"));
    (sender as RadComboBox).Items.Add(new RadComboBoxItem("Item2", "2"));
    (sender as RadComboBox).Items.Add(new RadComboBoxItem("Item3", "3"));
}
于 2010-02-05T19:20:24.103 に答える