AJAX的Telerik radcombobox控件。从第二个下拉框中获取的SelectedValue第二个、控件、框中、Telerik

2023-09-10 19:36:39 作者:一进一出一哆嗦

我想从另一个结果,即

ComboBox1的 - 自动完成和用户选择一个项目 在comboBox2 - 用户 选择。负载需求。使用来自ComboBox1的选择的价值 填充自己。 comboBox1 – autocompletes and user selects an item comboBox2 – user selects. Loads on demand. Uses the selected value from comboBox1 to populate itself.

问题是,我不能让ComboBox1的选定值

The problem is that I can’t get the selected value of combobox1

标记

<telerik:RadComboBox ID="comboBox1" runat="server" 
                 EnableLoadOnDemand="True" 
                 MarkFirstMatch="False" 
                 onitemsrequested="comboBox1_ItemsRequested" >
            </telerik:RadComboBox>

   <telerik:RadComboBox ID="comboBox2" runat="server" 
                 EnableLoadOnDemand="True" 
                 MarkFirstMatch="False" 
                 onitemsrequested="comboBox2_ItemsRequested" >
            </telerik:RadComboBox>

C#

protected void comboBox1_ItemsRequested(object sender, Telerik.Web.UI.RadComboBoxItemsRequestedEventArgs e)
{
    //.. populate this combo
}

protected void comboBox2_ItemsRequested(object sender, Telerik.Web.UI.RadComboBoxItemsRequestedEventArgs e)
{
    string test = comboBox1.SelectedValue;
    //.. test is empty. Why?? 
}

无奈的是,我不能得到所选择的值。这个问题可能是,页面是不实际回发(必须是问题的一部分),这样选择的值有没有机会进行设置。所以我写了code来解决这个问题。

Frustratingly I can’t get the selected value. The problem might be that the page isn’t actually posting back (must be part of the issue) so that selected value has no opportunity to be set. So I have written the code to get around this

标记

   <telerik:RadComboBox ID="comboBox1" runat="server" 
                 EnableLoadOnDemand="True" 
                 MarkFirstMatch="False" 
                 onitemsrequested="comboBox1_ItemsRequested" 
  onclientselectedindexchanged="OnClientSelectedIndexChanged">
            </telerik:RadComboBox>
   <asp:HiddenField runat="server" ID="hidClientId" />

   <telerik:RadComboBox ID="comboBox2" runat="server" 
                 EnableLoadOnDemand="True" 
                 MarkFirstMatch="False" 

                 onitemsrequested="comboBox2_ItemsRequested" >
            </telerik:RadComboBox>

JQuery的

JQuery

function OnClientSelectedIndexChanged(sender, eventArgs) {

         var item = eventArgs.get_item();
        var value = item.get_value();
        $("[ID$='hidClientId']").val(value);
}

C#

protected void comboBox2_ItemsRequested(object sender, Telerik.Web.UI.RadComboBoxItemsRequestedEventArgs e)
{
    string test = hidClientId. Value;
    //.. test is empty. Why?? 
}

这似乎我已经绕过回发的问题,但它仍然无法正常工作。

This would seem to me to have bypassed the postback issue but it still doesn’t work.

有谁知道如何让一个radcombobox控件从另一个价值?任何帮助非常AP preciated

Does anyone know how to get the value of one radComboBox from another? Any help greatly appreciated

推荐答案

可以不访问该网页上的其他控制的原因,是因为radcombobox控件执行一个异步请求的项目,因此在网页上的其他控制是不可访问。

The reason you cannot access the other controls on the page, is because the RadComboBox performs an Async request for the items and as such the other controls on the page are not accessible.

尝试处理 OnClientItemsRequesting 事件,利用上下文对象(即传递到服务器端code)发送第一个选定值组合。

Try handling the OnClientItemsRequesting event, making use of the context object (that is passed to the server-side code) to send the selected value of the first combo.

标记

<telerik:RadCodeBlock ID="RadCodeBlock" runat="server">

    <script type="text/javascript">

        function OnClientItemsRequesting(sender, eventArgs) {

            var comboBox1 = $find('<%= comboBox1.ClientID %>');
            var value = comboBox1.get_value();

            var context = eventArgs.get_context();
            context["ComboBox1Value"] = value;
        }

    </script>

</telerik:RadCodeBlock>

<telerik:RadComboBox ID="comboBox1" runat="server" 
    MarkFirstMatch="False">
    <Items>
        <telerik:RadComboBoxItem Text="Item 1" Value="0" />
        <telerik:RadComboBoxItem Text="Item 2" Value="1" />
    </Items>
</telerik:RadComboBox>

<telerik:RadComboBox ID="comboBox2" runat="server" 
            EnableLoadOnDemand="True" 
            MarkFirstMatch="False" 
            onitemsrequested="comboBox2_ItemsRequested"
            OnClientItemsRequesting="OnClientItemsRequesting">
</telerik:RadComboBox>            

$ C $后面ç

protected void comboBox2_ItemsRequested(object sender, Telerik.Web.UI.RadComboBoxItemsRequestedEventArgs e)
{
    string selectedValue = e.Context["ComboBox1Value"].ToString();
}

希望这有助于。

Hope this helps.