リピータ内Telerik RadComboBoxを使用して
-
18-09-2019 - |
質問
私はTelerik RadComboBoxが含まれているリピーターを持っています:
<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>
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イベントを配線することは問題があると思われるが、問題は別の場所にあるのかもしれない。
リピータ内Telerik RadComboBoxを使用する方法上の任意のアイデア適切に?
解決
あなたが動的にそれを追加するのではなく、マークアップでイベントハンドラの配線を入れてみましたか?
また、 - あなたはおそらく認識していますが、念のために - 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イベントは、すべてのコンボボックスのために発射し、オンザフライでドロップダウンに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"));
}