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

Load on Demand and Edit

1 Answer 51 Views
ComboBox
This is a migrated thread and some comments may be shown as answers.
archimede
Top achievements
Rank 1
archimede asked on 11 Nov 2010, 10:49 AM
I want to use LoadOnDemand for a combobox. The comboBox is:

<telerik:RadComboBox ID="rcbProva" runat="server" EmptyMessage="Seleziona..." EnableLoadOnDemand="true" OnItemsRequested="rcbProva_ItemsRequested">
</telerik:RadComboBox>

I want to bind the radComboBox with a selectedValue but it seems not to work .
How can I set the SelectedValue of a RadComboBox using EnableLoadOnDemand=true? Anyone has an example?

1 Answer, 1 is accepted

Sort by
0
Shinu
Top achievements
Rank 2
answered on 11 Nov 2010, 02:22 PM
Hello Archimede,

Since you set the EnableLoadOnDemand to true, the combo will populate only when the user types the text or clicks on the drop-down toggle image. If you want to bind the RadComboBox with a SelectedValue you can try to add the item on page load.

C#:
protected void Page_Load(object sender, EventArgs e)
   {
       if (!IsPostBack)
       {
           string value = "3";
           SqlConnection con = new SqlConnection(WebConfigurationManager.ConnectionStrings["NorthwindConnectionString"].ConnectionString);
           SqlCommand cmd = new SqlCommand("select EmployeeID,FirstName from Employees where EmployeeID='" + value + "'", con);
           SqlDataAdapter da = new SqlDataAdapter(cmd);
           DataTable dt = new DataTable();
           da.Fill(dt);
           RadComboBoxItem item = new RadComboBoxItem(dt.Rows[0]["FirstName"].ToString());
           rcbProva.Items.Add(item);
           rcbProva.Items[0].Selected = true;
       }
   }

You can find another approach in the following forum post.
http://www.telerik.com/community/forums/aspnet-ajax/combobox/set-default-value-selected-in-combobox-at-page-load.aspx#1299910


-Shinu.
Tags
ComboBox
Asked by
archimede
Top achievements
Rank 1
Answers by
Shinu
Top achievements
Rank 2
Share this question
or