2

我在用户控件中有一个 RadCombobox,我试图从 Javascript 将值设置为 null 或 0。以下代码不起作用。但它也没有显示任何错误。

function OnClientSelectedIndexChanged(sender, eventArgs) {
    var item = eventArgs.get_item();
        var ddl = document.getElementById('ctl00_plh1_Test1_Dropdown2_RadComboBox1_DropDown');
        ddl.selectedIndex = 0;

}

<telerik:RadComboBox ID="Dropdown1" runat="server" 
                             NoWrap="true" Width="250" OnClientSelectedIndexChanged="OnClientSelectedIndexChanged">
                            <CollapseAnimation Duration="200" Type="OutQuint" />
                        </telerik:RadComboBox>



<uc2:RadComboBox ID="Dropdown2" runat="server" DdlAutoWidth="true"></uc2:RadComboBox>
4

5 回答 5

3

尝试这个。

var mycombobox = $find("<%= MyUserControl.FindControl("RadComboBox1").ClientID %>");

或者

var mycombobox = $find("<%= RadComboBox1").ClientID %>");

mycombobox.clearSelection();

你可能需要这个

<rad:RadScriptBlock runat="server" ID="RadCodeBlock">
   <script type="text/javascript">

   </script>
</rad:RadScriptBlock>
于 2012-07-12T16:28:21.457 回答
1

I assume the RadComboBox that will trigger the OnClientSelectedIndexChanged event will have 2 or more RadCombBoxItems, otherwise the event will never be fired as the selected index can never change.

When the event fires, you must get a reference to the RadComboBox control inside your UserControl. To set it's SelectedIndex property to 0 you call the set_selectedIndex() function on the client-side control. Keep in mind that this only sets the SelectedIndex, and does not update the text in the input field of the RadComboBox. If you want to clear that out as well you must call the client-side control's set_text() function.

function onComboBoxSelectedIndexChanged(s, e) {
    var ctrl = '<%= Dropdown2.FindControl("RadComboBox1").ClientID %>';
    if (ctrl) {
        ctrl.set_selectedIndex(0);
        ctrl.set_text('');
    } 
}

Please refer to the documentation on Telerik's website for more information regarding the JavaScript API for the RadCombBox control.

于 2012-07-13T16:11:12.293 回答
0

尝试:

var radComboBox = <%=YourComboBox.ClientID %>;  

radComboBox.SetValue("someValue"); 
于 2012-07-12T22:31:05.567 回答
0

您要设置什么0null选择的值或选择的索引?
试试这个选定的值:

$find("<%=ctl00_plh1_Test1_Dropdown2_RadComboBox1_DropDown.ClientID%>").set_text("0");
于 2013-03-04T09:43:10.267 回答
0

试试这个在javascript中选择的值:

var SelectdVal=1;
$find("<%= YourRadComboBox.ClientID %>").findItemByValue(SelectdVal).select();
于 2021-08-06T12:55:24.043 回答