在中继器中使用 Telerik RadComboBox

发布于 2024-08-20 14:19:31 字数 1024 浏览 6 评论 0原文

我有一个包含 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>

在转发器的 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 有什么想法吗?

I have a repeater that contains a 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>

In the ItemDataBound event of the Repeater, I am wiring up the ItemsRequested event like this:

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.
}

Currently, the server-side rcb_ItemsRequested method is never called. I suspect that wiring the ItemsRequested event in the ItemDataBound is problematic, but the problem may lie elsewhere.

Any ideas on how to use the Telerik RadComboBox within a repeater properly?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

情未る 2024-08-27 14:19:31

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

另外 - 您可能知道,但以防万一 - 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"));
}

Have you tried putting the event handler wiring in the markup rather than adding it dynamically?

Also - you are probably aware, but just in case - ItemsRequested is an event that only fires under certain conditions. To quote the docs:

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. - Reference

Does your scenario match the above?

EDIT:

I've tested some code. The following works (The ItemsRequested Event fires for the all ComboBoxes and adds the three test items to the dropdown on the fly..):

Markup:

<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>

code behind:

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"));
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文