2010-02-05 79 views
2

我有一个包含一个Telerik的radcombobox控件转发:中继器内使用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的任何想法?

回答

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

请问您的方案符合以上?

编辑

我测试过的一些代码。以下作品(该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")); 
} 
+0

我确实尝试在标记中连接事件无济于事。好的建议,但。顺便说一句,我相信你从文档中引用的EnabledLoadOnDemand实际上是EnableLoadOnDemand;我尝试了两种,但没有运气。 我相信我满足所有必要的条件(我们在整个应用程序中使用RadComboBox - 只是不在中继器 - 所以我熟悉它的使用)。 感谢您的建议。我会更详细地研究这一点;当然我愿意接受任何进一步的想法。 – mcliedtk 2010-02-05 19:37:03

+0

大声笑是啊,我没有注意到错字。这是直接从供应商文档复制的。我认为你是对的 - 它是EnableLoadOnDemand。 – 2010-02-05 20:07:01

+0

我已经添加了一个工作代码示例..希望它可以帮助.. – 2010-02-05 20:35:33

相关问题