views:

974

answers:

1

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?

+1  A: 

Hi,

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"));
}
KP
I did try wiring the event in the markup to no avail. Good suggestion, though. Incidentally, I believe the EnabledLoadOnDemand as you quoted from the documentation is in fact EnableLoadOnDemand; I tried both, but no luck yet.I believe I am satisfying all the conditions necessary (we use the RadComboBox throughout our application - just not in repeaters - so I am familiar with its use).Thanks for your suggestions. I will look into this in more detail; of course I am open to any further ideas you may have.
mcliedtk
lol yeah I didn't notice the typo. That was copied directly from the vendor documentation. I think you're right - it's EnableLoadOnDemand.
KP
I've added a working code sample.. hope it helps..
KP
So in fact you were correct in suggesting that the wiring of events must occur in the markup. I was just being myopic and added ItemsRequested="rcb_ItemsRequested" instead of the correct OnItemsRequested="rcb_ItemsRequested". That has solved the problem!
mcliedtk
Interesting that your code sample works with the event wiring in the code behind. I'll have to ponder that on another day.
mcliedtk