This is a migrated thread and some comments may be shown as answers.

SelectedIndexChanged Not Firing on certain RadComboBoxes

3 Answers 293 Views
ComboBox
This is a migrated thread and some comments may be shown as answers.
pmourfield
Top achievements
Rank 1
pmourfield asked on 06 Oct 2011, 07:27 PM
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();
        }

3 Answers, 1 is accepted

Sort by
0
pmourfield
Top achievements
Rank 1
answered on 06 Oct 2011, 08:16 PM
Found the answer. The problem was that I was not setting the item.Text and item.Value for the RadComboBoxItem within the foreach loop.
0
Shahzad Ilyas
Top achievements
Rank 2
answered on 19 Oct 2011, 09:49 AM
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
0
Shahzad Ilyas
Top achievements
Rank 2
answered on 19 Oct 2011, 02:25 PM
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
Tags
ComboBox
Asked by
pmourfield
Top achievements
Rank 1
Answers by
pmourfield
Top achievements
Rank 1
Shahzad Ilyas
Top achievements
Rank 2
Share this question
or