Dropdown List with RadComboBox

2 posts, 0 answers
  1. Greg
    Greg avatar
    6 posts
    Member since:
    Mar 2012

    Posted 28 Feb 2013 Link to this post

    I have a datalist (dlLockNumber) with a RadComboBox Control (rcbLockSeriesLockNumbers) in it. Depending on the number of records in the datalist, there could be one to 100 (or more) RadComboBox instances of rcbLockSeriesLockNumbers. I have a RadButton named "rbSelect" for each RadComboBox that is disabled upon page load - so that when someone selects some value other than the default ("-1"), the desired event is to enable the button. I have a javascript function named OnClientSelectedIndexChanged that hopefully would work but it does not. If any of you Javascript sharpies could take a look at the function and steer me in the right direction, it would be appreciated.

    Here is the HTML side of the code - this is part of a .NET User Control:
    <%@ Control Language="VB" AutoEventWireup="false" CodeFile="Keys.ascx.vb" Inherits="Controls_Keys" %>
    <telerik:RadCodeBlock ID="rcblock1" runat="server">
    <script language="javascript" type="text/javascript">
        function OnClientSelectedIndexChanged(sender, eventArgs) {
            var item = eventArgs.get_item();
            var ddl = $find("<%= dlKeySeries.ClientID %>");
            var button = ddl.get_items().getItem(0).findControl("rbSelect");
            var strValue = item.options[item.selectedIndex].value;
            if (strValue == "-1") {
                button.set_enabled(false);
            }
            else {
                button.set_enabled(true);
            }
        }
    </script>
    </telerik:RadCodeBlock>
    <telerik:RadAjaxPanel ID="rapKeys" runat="server">
    <asp:Panel ID="pnlKeysTrue" Visible="true" runat="server">
    <table width="100%" align="center" border="0" cellpadding="0" cellspacing="0">
        <tr>
            <td class="BlackSmall">
            <br />
                <asp:Literal ID="litSectionTitle" runat="server" /><br />
                <asp:Literal ID="litSectionIntro" runat="server" />
            </td>
        </tr>
        <tr id="trrcKeySeries" runat="server">
            <td class="BlackSmall">
                <br />
                <asp:DataList ID="dlLockNumber" DataKeyField="SeriesLockID" OnItemDataBound="dlLockNumber_ItemDataBound" Width="100%" RepeatDirection="Vertical" RepeatColumns="3" runat="server">
                    <ItemTemplate>
                        <asp:Label ID="lblSeriesLockID" Visible="false" runat="server"><%#Databinder.Eval(Container.DataItem, "SeriesLockID") %></asp:Label>
                        <table border="0" cellpadding="0" cellspacing="0">
                            <tr>
                                <td valign="top" style="width:196px;text-align:center">
                                    <telerik:RadComboBox ID="rcbLockSeriesLockNumbers" OnClientSelectedIndexChanged="OnClientSelectedIndexChanged" CausesValidation="false" AppendDataBoundItems="true" DataValueField="LockNumberID" Width="130px" ZIndex="20000" DataTextField="LockNumber" AutoPostBack="true" runat="server"  />
                                </td>
                                <td>
                                    <telerik:RadButton ID="rbSelect" Enabled="false" Skin="Sunset" OnClick="rbSelect_OnClick" runat="server" Text="Select" />
                                </td>
                            </tr>
                        </table>
                    </ItemTemplate>
                </asp:DataList>
            </td>
        </tr>
    </table>
    </asp:Panel>
  2. Hristo Valyavicharski
    Admin
    Hristo Valyavicharski avatar
    975 posts

    Posted 01 Mar 2013 Link to this post

    Hello Greg,

    With the current implementation the button is enabled in the ClientSelectedIndexChanged event, at the same time you have AutoPostBack="true" which will cause a post back once the selection is changed. Since the RadButton does not persists its enabled value when changed client-side, my suggestion is to change it in the server SelectedIndexChanged event of the RadComboBox.

    Greetings,
    Hristo Valyavicharski
    the Telerik team
    If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to their blog feed now.
Back to Top