在中继器内使用Telerik RadComboBox

在中继器内使用Telerik RadComboBox,telerik,repeater,radcombobox,Telerik,Repeater,Radcombobox,我有一个包含Telerik RadComboBox的中继器: <asp:Repeater ID="rpt" runat="server"> <ItemTemplate> <telerik:RadComboBox ID="rcb" runat="server" EnableLoadOnDemand="true" AllowCustomText="true" ItemRequestTimeout="1000"

我有一个包含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>
目前,从未调用服务器端rcb_ItemsRequested方法。我怀疑在ItemDataBound中连接ItemsRequested事件有问题,但问题可能出在其他地方


关于如何在中继器中正确使用Telerik RadComboBox有什么想法吗?

您是否尝试过将事件处理程序连接放入标记中,而不是动态添加它

另外-您可能知道,但以防万一-ItemsRequested是仅在特定条件下触发的事件。引用文件:

当EnabledLoadOnDemand属性为True且用户在输入字段中键入文本或在列表为空时单击下拉切换图像时,会发生ItemsRequested事件。
-

您的场景是否符合上述要求

编辑

我已经测试了一些代码。以下工作(ItemsRequested事件为所有组合框触发,并将三个测试项添加到动态下拉列表中..):

标记:

<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"));
}
受保护的无效页面加载(对象发送方,事件参数e)
{
列表数据=新列表();
数据。添加(“第1项”);
数据。添加(“第2项”);
//向中继器添加一些项以强制其绑定并重复。。
rpt.DataSource=数据;
rpt.DataBind();
}
受保护的void rpt_ItemDataBound(对象发送方,RepeaterItemEventArgs e)
{
//连线活动
RadComboBox rcb=(RadComboBox)e.Item.FindControl(“rcb”);
rcb.ItemsRequested+=rcb_ItemsRequested;
}
受保护的无效rcb_项请求(对象发送方,RadComboBoxItemsRequestedEventArgs e)
{
//在需要时添加项目。
(作为RadComboBox的发送者)。Items.Add(新的RadComboBoxItem(“Item1”,“1”));
(作为RadComboBox的发送者)。Items.Add(新的RadComboBoxItem(“Item2”,“2”));
(发送方为RadComboBox).Items.Add(新RadComboBoxItem(“Item3”、“3”));
}

我尝试将事件关联到标记中,但没有成功。好的建议。顺便说一句,我相信您从文档中引用的EnabledLoadOnDemand实际上是EnabledLoadOnDemand;我两个都试过了,但都不走运。我相信我满足了所有必要的条件(我们在整个应用程序中使用RadComboBox—只是不在中继器中—所以我熟悉它的使用)。谢谢你的建议。我将更详细地研究这一点;当然,我愿意接受你的任何进一步想法。哈哈,是的,我没有注意到打字错误。这是直接从供应商文档中复制的。我认为你是对的-它是EnableLoadOnDemand。因此,事实上,你正确地建议事件的连接必须发生在标记中。我只是目光短浅,添加了ItemsRequested=“rcb\u ItemsRequested”而不是正确的OnItemsRequested=“rcb\u ItemsRequested”。这就解决了问题!有趣的是,您的代码示例使用代码隐藏中的事件连接。改天我得考虑一下。
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"));
}