【问题标题】:Using Telerik RadComboBox within a repeater在中继器中使用 Telerik RadComboBox
【发布时间】:2010-02-05 18:44:54
【问题描述】:

我有一个包含 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 有什么想法吗?

【问题讨论】:

    标签: telerik repeater radcombobox


    【解决方案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. - Reference

    你的场景是否符合上述情况?

    编辑

    我已经测试了一些代码。以下工作(为所有 ComboBox 触发 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"));
    }
    

    【讨论】:

    • 我确实尝试在标记中连接事件但无济于事。不过建议不错。顺便说一句,我相信您从文档中引用的 EnabledLoadOnDemand 实际上是 EnableLoadOnDemand;我都试过了,但还没有运气。我相信我满足了所有必要的条件(我们在整个应用程序中使用 RadComboBox - 只是不在中继器中 - 所以我熟悉它的使用)。感谢您的建议。我会更详细地研究这个;当然,我对您可能有的任何进一步的想法持开放态度。
    • 大声笑是的,我没有注意到错字。那是直接从供应商文档中复制的。我认为你是对的 - 它是 EnableLoadOnDemand。
    • 所以事实上你正确地建议事件的连接必须发生在标记中。我只是近视并添加了 ItemsRequested="rcb_ItemsRequested" 而不是正确的 OnItemsRequested="rcb_ItemsRequested"。这样就解决了问题!
    • 有趣的是,您的代码示例与后面代码中的事件连接一起工作。我得改天再考虑。
    猜你喜欢
    • 1970-01-01
    • 2014-12-29
    • 1970-01-01
    • 2015-01-12
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2010-12-22
    • 1970-01-01
    相关资源
    最近更新 更多