Bind RadComboBox to ObjectDataSource using DataSet

1.4k Views Asked by At

I'm trying to bind a RadComboBox to an ObjectDataSource whose select method returns a DataSet object. I get an error: "'FieldName', is neither a DataColumn nor a DataRelation for table Table". Just to be sure I'm not crazy, I tried the same with a DropDownList which worked perfectly. I found in Telerik's docs that they support using an ObjectDataSource that returns IEnumerable objects. So, am I correct that the RadControls don't support using ObjectDataSource when it is using a DataSet? Really?

1

There are 1 best solutions below

6
On

The link you provided points to a different control. See here for the combobox, which is the control in your question title.

The combobox control easily accepts datatable objects from datasets as a source of what to display in the combobox.

enter image description here

Then the combobox control:

enter image description here

Select the GetData method (the only option) and then configure your combobox:

enter image description here

Run:

enter image description here

EDIT:

There seems to be no reason to use a ObjectDataSource if you are already using a dataset and SqlDataAdapter :

    DataSet myDataset = new DataSet();

    SqlConnection con = new SqlConnection(@"Data Source=J-PC\SQLEXPRESS;Initial Catalog=SO;Integrated Security=True");

    SqlDataAdapter adapter = new SqlDataAdapter(@"SELECT TOP (25) Leg_FirstName FROM GRS_Legislator ORDER BY Leg_FirstName", con);

    adapter.Fill(myDataset);

    RadComboBox1.DataTextField = "Leg_FirstName";
    RadComboBox1.DataValueField = "Leg_FirstName";
    RadComboBox1.DataSource = myDataset;
    RadComboBox1.DataBind();