2010-02-05 33 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

相關問題