ComboBox EmptyMessage SelectedIndexChanged

3 posts, 1 answers
  1. Aurore
    Aurore avatar
    58 posts
    Member since:
    Nov 2007

    Posted 07 Dec 2009 Link to this post

    Hello,

    I have a grid, and a combobox.
    When multiple row are selected in the grid, I test if the values for a certain column are equals, if so, I found this value in the combobox, if not, I set an empty message to the combobox.

    Suppose there's 3 rows in my grid :
    row1 : a ; g1
    row2 : b ; g1
    row3 : c ; g3

    because g1 != g3, combobox is setting to the empty message ("choose a group").

    Now, user can choose the group to put a, b and c.  I need to detect the ClientSelectedIndexChanged event. But it seems that passing from empty message to an element of my combobox doesn't raise the event.

    Below, the code I used.

     <tlk:RadAjaxPanel ID="AjaxPnl" runat="server" LoadingPanelID="oAjaxPanel"  
            OnAjaxRequest="AjaxPnlRequest"
    <tlk:RadComboBox ID="oModCombo" runat="server" MarkFirstMatch="true" style="margin-top:5px; float:right; margin-right:5px;"  
                EmptyMessage="Choisir un groupe..." AllowCustomText="true" 
                OnClientSelectedIndexChanged="oGroupModSelectedIndexChanged"  
                OnClientTextChange="oGroupModTextChange" /> 
             
            <tlk:RadGrid ID="modgrid" runat="server" OnNeedDataSource="modgrid_OnNeedDataSource"  
                Height="215" Width="95%" style="margin-top:30px;margin-left:5px;" 
                AutoGenerateColumns="false" AllowMultiRowSelection="true" > 
                <MasterTableView > 
                <Columns> 
                <tlk:GridBoundColumn DataField="id"  Visible="false"/> 
                <tlk:GridBoundColumn AllowSorting="true" HeaderText="Modalités" DataField="mod"
                </tlk:GridBoundColumn> 
                <tlk:GridBoundColumn AllowSorting="true" HeaderText="Status" DataField="status">   
                <HeaderStyle Width="150" /> 
                </tlk:GridBoundColumn>             
                <tlk:GridBoundColumn DataField="gpvalue" ReadOnly="true" Display="false"
                <HeaderStyle Width="0" /> 
                <ItemStyle  ForeColor="White" Width="0"/> 
                </tlk:GridBoundColumn> 
                </Columns> 
                </MasterTableView> 
                <ClientSettings  > 
                <Scrolling AllowScroll="true" UseStaticHeaders="true" /> 
                <Selecting AllowRowSelect="true" EnableDragToSelectRows="true" /> 
                <ClientEvents OnRowSelected="ModalitiesSelected" OnRowDeselected="ModalitiesDeselected" /> 
                </ClientSettings> 
            </tlk:RadGrid> 
        </tlk:RadAjaxPanel> 
             
            <tlk:RadCodeBlock runat="server" ID="rcb2"
     
            <script type="text/javascript" language="javascript">        
            function AjaxPnlRequest(requestName) 
            { 
                 var manager = <%= AjaxPnl.ClientID %>;  
                manager.ajaxRequest(requestName); 
            } 
            </script>         
             </tlk:RadCodeBlock> 
    var bNotPostback = true
            var bAllEquals = true
            var sValue = null
            var iHandled = -1; 
            var bMade = false
            function ModalitiesSelected() { 
                var grid = $find("<%=modgrid.ClientID %>"); 
                var MasterTable = grid.get_masterTableView(); 
                var selectedRows = MasterTable.get_selectedItems(); 
                //alert(iHandled + " " + selectedRows.length); 
                if (selectedRows.length == 1) { 
                    bAllEquals = true
                    iHandled = 1;bMade = false
                    sValue = MasterTable.getCellByColumnUniqueName(selectedRows[0], "gpvalue").innerHTML
                } 
                else { 
                    var row = selectedRows[selectedRows.length - 1]; 
                    bMade = false
                    var cell = MasterTable.getCellByColumnUniqueName(row, "gpvalue"); 
                    bAllEquals = (sValue == cell.innerHTML); 
                    iHandled += 1; 
                } 
                window.setTimeout(function() { setCombo(); }, 500); 
            } 
     
            function ModalitiesDeselected() { 
                var grid = $find("<%=modgrid.ClientID %>"); 
                var MasterTable = grid.get_masterTableView(); 
                var selectedRows = MasterTable.get_selectedItems(); 
                iHandled = selectedRows.length; 
                if (iHandled > 0) { 
                    bMade = false
                    bAllEquals = true
                    sValue = MasterTable.getCellByColumnUniqueName(selectedRows[0], "gpvalue").innerHTML
                    var i = 1; 
                    while ((i < iHandled) && bAllEquals) { 
                        var cell = MasterTable.getCellByColumnUniqueName(selectedRows[i], "gpvalue"); 
                        bAllEquals = (sValue == cell.innerHTML); 
                        i++; 
                    } 
                    setCombo(); 
                } 
                else { 
                    var oCombo = $find("<%=oModCombo.ClientID %>"); 
                    oCombo.clearSelection(); 
                    oCombo.disable(); 
                    oCombo.set_emptyMessage(oCombo.get_emptyMessage());  
                } 
            } 
     
            function setCombo() { 
                var grid = $find("<%=modgrid.ClientID %>"); 
                var MasterTable = grid.get_masterTableView(); 
                var selectedRows = MasterTable.get_selectedItems(); 
                if ((iHandled == selectedRows.length) && (bMade == false)) { 
                    //alert("setCombo " + iHandled + " " + selectedRows.length); 
                    bNotPostback = true;bMade = true
                    var oCombo = $find("<%=oModCombo.ClientID %>"); 
                    oCombo.clearSelection(); 
                    oCombo.enable(); 
                    if (bAllEquals) { 
                        var item = oCombo.findItemByValue(sValue); 
                        if (item) item.select(); 
                    } 
                    else { 
                        oCombo.set_emptyMessage(oCombo.get_emptyMessage()); 
                        //oCombo.set_text(oCombo.get_emptyMessage()); 
                    } 
                } 
            } 
             
            
            function oGroupModSelectedIndexChanged(sender, args) { 
                if (bNotPostback) bNotPostback = false
                else { 
                    var sArg = "oModCombo;"
                    var item = args.get_item(); 
                    sArg += item.get_text() + ";" + item.get_value(); 
                    AjaxPnlRequest(sArg); 
                } 
            } 
     
            function oGroupModTextChange(sender, args) { 
                var sArg = "oModCombo;"
                sArg += sender.get_text() + "; "
                AjaxPnlRequest(sArg); 
            } 
             


    Thanks for your help.
    Aurore

  2. Answer
    Veselin Vasilev
    Admin
    Veselin Vasilev avatar
    2992 posts

    Posted 10 Dec 2009 Link to this post

    Hi Aurore,

    I tried to reproduce the problem with this very simple code, but to no avail:

    <asp:Button ID="Button1" runat="server" Text="Button" OnClientClick="onClientClick()" />
             
    <telerik:RadComboBox ID="RadComboBox1" runat="server"
        AllowCustomText="true"
        OnClientSelectedIndexChanged="onSelectedIndexChanged"
        EmptyMessage="select">
        <Items>
            <telerik:RadComboBoxItem Text="111" />
            <telerik:RadComboBoxItem Text="222" />
        </Items>
    </telerik:RadComboBox>
             
    <script type="text/javascript">
        function onSelectedIndexChanged(sender, e) {
            alert("onSelectedIndexChanged fired");
        }
     
        function onClientClick() {
            $find("RadComboBox1").get_items().getItem(1).select();
        }
         
    </script>


    Regards,
    Veselin Vasilev
    the Telerik team

    Instantly find answers to your questions on the new Telerik Support Portal.
    Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
  3. Aurore
    Aurore avatar
    58 posts
    Member since:
    Nov 2007

    Posted 18 Dec 2009 Link to this post

    Hello,

    Thank's.
    You've right, your controls work perfectly.

    It was my javascript boolean treatment which contained an error.

    Aurore
Back to Top