SelectedIndexChanged Not Firing on certain RadComboBoxes

4 posts, 0 answers
  1. pmourfield
    pmourfield avatar
    32 posts
    Member since:
    Aug 2011

    Posted 06 Oct 2011 Link to this post

    For some reason my combobox will not fire its SelectedIndexChanged method. I created another combobox just below it without any header or item templates and its selectedindexchanged works just fine. Can anyone tell me why the code below is not working?

    <telerik:RadComboBox ID="employeeList" runat="server" Height="200px" Width="300px"
                DropDownWidth="300px" HighlightTemplatedItems="true" CausesValidation="false"
                EnableLoadOnDemand="true" EmptyMessage="Choose and Employee"
                Filter="StartsWith" AutoPostBack="true"
                onitemsrequested="employeeList_ItemsRequested"
                onselectedindexchanged="employeeList_SelectedIndexChanged">
                <HeaderTemplate>
                    <table>
                        <tr>
                            <td style="width: 150px;">
                                Employee Name
                            </td>
                            <td style="width: 200px;">
                                Employee UserName
                            </td>
                        </tr>
                    </table>
                </HeaderTemplate>
                <ItemTemplate>
                    <table style="width: 300px" cellspacing="0" cellpadding="0">
                        <tr>
                            <td style="width: 150px">
                                <%# DataBinder.Eval(Container, "Attributes['Name']") %>
                            </td>
                            <td style="width: 150px">
                                <%# DataBinder.Eval(Container, "Attributes['ID']") %>
                            </td>
                        </tr>
                    </table>
                </ItemTemplate>
            </telerik:RadComboBox>
    protected void employeeList_ItemsRequested(object sender, RadComboBoxItemsRequestedEventArgs e)
            {
                SqlConnection connection = new SqlConnection(GetConnectionString());
                connection.Open();
                SqlCommand cmd = new SqlCommand();
                //DataTable dt = new DataTable();
                cmd = new SqlCommand("DisplayEmployeeNamesForDropDown", connection);
                cmd.CommandType = CommandType.StoredProcedure;
                cmd.Parameters.Add(new SqlParameter("@ManagerID", TimeSlayer.ActiveDirectoryUser.UserName(User)));
                //SqlDataAdapter da = new SqlDataAdapter(cmd);
                //da.Fill(dt);
     
                SqlDataReader dr;
                dr = cmd.ExecuteReader();
     
                //populate combo box for goal review form
     
                //foreach (DataRow row in dt.Rows)
                //{
                //    employeeComboBox.Items.Add(new RadComboBoxItem(row[1].ToString(), row[0].ToString()));               
                //}
     
                foreach (IDataRecord record in dr)
                {
                    RadComboBoxItem item = new RadComboBoxItem();
     
                    //item.Text =
                    //item.Value = record["Name"].ToString();
     
                    item.Attributes.Add("ID", record["ID"].ToString());
                    item.Attributes.Add("Name", record["Name"].ToString());
     
     
                    employeeList.Items.Add(item);
                    item.DataBind();
               }
     
                cmd.Connection.Close();
                cmd.Connection.Dispose();
            }
  2. pmourfield
    pmourfield avatar
    32 posts
    Member since:
    Aug 2011

    Posted 06 Oct 2011 Link to this post

    Found the answer. The problem was that I was not setting the item.Text and item.Value for the RadComboBoxItem within the foreach loop.
  3. Shahzad Ilyas
    Shahzad Ilyas avatar
    4 posts
    Member since:
    Feb 2010

    Posted 19 Oct 2011 Link to this post

    Hi Joshua

    i have slightly different problem. i have the same snario and im setting item.text and item.value as well in foreach loop. but unable to fire onselectedindexchanged on radcombobox. and my autopostback=true as well

    it seems that asp.net engine holds the postback for some reason and fires only when other asp.net controls makes a postback.

    1) selecting index on radcombobox holds postback
    2) fires only when other asp.net controls makes postback.


    your help is higly appriciated
    regards
    shaz
  4. Shahzad Ilyas
    Shahzad Ilyas avatar
    4 posts
    Member since:
    Feb 2010

    Posted 19 Oct 2011 Link to this post

    Hi 
    found the solution thanks to Shinu..:D

    Quote "One suggestion would be invoking postback from client side SelectionIndexChanged event of RadComboBox instead of setting the AutoPostBack property to True. Give a try with the following code."


    ASPX
    <telerik:RadComboBox ID="RadComboBox1" runat="server" AutoPostBack="false" AllowCustomText="True" OnSelectedIndexChanged="RadComboBox1_SelectedIndexChanged"
        OnClientSelectedIndexChanged="OnClientSelectedIndexChanged">
        <Items>
            <telerik:RadComboBoxItem runat="server" Text="RadComboBoxItem1" Value="RadComboBoxItem1">
            </telerik:RadComboBoxItem>
         </Items>
    </telerik:RadComboBox>


    JavaScript
    <script type="text/javascript">
    function OnClientSelectedIndexChanged(sender, args)
    {
    __doPostBack('RadComboBox1','');
    }
    </script>

    thank you so much
    regards
    Shaz
Back to Top