RadComboBox Selected Value is null

3 posts, 0 answers
  1. Emre
    Emre avatar
    2 posts
    Member since:
    Nov 2011

    Posted 11 Nov 2011 Link to this post

    Hello,

    I have a RadComboBox. The data comes from MsSql.
    I want to take selectedvalue when the selectedindexchanged, but the value equal null.

    My RadComboBox
    <telerik:RadComboBox ID="RadComboBox1" runat="server" Width="350px"
         EnableLoadOnDemand="True" onitemsrequested="RadComboBox1_ItemsRequested"
         onselectedindexchanged="RadComboBox1_SelectedIndexChanged"
         ExpandDirection="Up" AutoPostBack="True" AppendDataBoundItems="True">
    </telerik:RadComboBox>

    ItemsRequested
    protected void RadComboBox1_ItemsRequested(object o, Telerik.Web.UI.RadComboBoxItemsRequestedEventArgs e)
            
     {
                Telerik.Web.UI.RadComboBox combo = (Telerik.Web.UI.RadComboBox)o;
     
                SqlDataAdapter da = new SqlDataAdapter("SELECT iladi from iller WHERE iladi LIKE '" + e.Text + "%'", MyConnection);
     
                DataTable dt = new DataTable();
                da.Fill(dt);
     foreach (DataRow row in dt.Rows)
                {
                 Telerik.Web.UI.RadComboBoxItem item = new Telerik.Web.UI.RadComboBoxItem(row["iladi"].ToString());
     
                 combo.Items.Add(item);
                }
            }

    SelectedIndexChanged value equal null but when I select a value from radcombobox  RadComboBox1.SelectedValue must equal selected.


    protected void RadComboBox1_SelectedIndexChanged(object sender, Telerik.Web.UI.RadComboBoxSelectedIndexChangedEventArgs e)
            {
                //Label1.Text = RadComboBox1.SelectedItem.ToString();
                Label1.Text = RadComboBox1.SelectedValue.ToString();
            }
  2. Princy
    Princy avatar
    17421 posts
    Member since:
    Mar 2007

    Posted 13 Nov 2011 Link to this post

    Hello Emre,

    I have tried the same but no avail. The SelectedIndexChanged event occurs when the user selects a new item in the drop-down list. Here is the code.

    protected void RadComboBox_ItemsRequested(object sender, Telerik.Web.UI.RadComboBoxItemsRequestedEventArgs e)
       {
         SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["NorthwindConnectionString"].ToString());
         String s = "select FirstName,EmployeeID from Employees";
         con.Open();
         SqlDataAdapter dr = new SqlDataAdapter(s, con);
         DataTable dt = new DataTable();
         dr.Fill(dt);
         con.Close();
         RadComboBox1.DataSource = dt;
         RadComboBox1.DataTextField = "FirstName";
         RadComboBox1.DataValueField = "EmployeeID";
         RadComboBox1.DataBind();
       }
       protected void RadComboBox1_SelectedIndexChanged(object sender, RadComboBoxSelectedIndexChangedEventArgs e)
       {
         Label Label1 = new Label();
         Label1 .Text = RadComboBox1.SelectedValue.ToString();
         form1.Controls.Add(Label1 );
       }

    Thanks,
    Princy.
  3. Emre
    Emre avatar
    2 posts
    Member since:
    Nov 2011

    Posted 15 Nov 2011 Link to this post

    Thanks Princy,
    it is worked.
Back to Top