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

Dyanamic Data Binding

3 Answers 66 Views
ComboBox
This is a migrated thread and some comments may be shown as answers.
Ali
Top achievements
Rank 1
Ali asked on 04 Apr 2011, 10:08 PM
Hello All,

I'm new to Telerik controls. I'm sure this must be a simple one but wasn't able to figure out in the documentation. I would like to bind the combo box with the dataset I create dynamically instead of using SQL object datasource control.

Any help would be appreciated.

Thanks.

3 Answers, 1 is accepted

Sort by
0
Accepted
Shinu
Top achievements
Rank 2
answered on 05 Apr 2011, 05:16 AM
Hello Ali,
Here is a sample code to achieve the same.
C#:
protected void Page_Load(object sender, EventArgs e)
   {
       if (!IsPostBack)
       {
           DataTable dataTable = CreateDataSource();
           RadComboBox2.DataSource = CreateDataSource();
           RadComboBox2.DataTextField = "Name";
           RadComboBox2.DataValueField = "ID";
           RadComboBox2.DataBind();
       }
   }
protected DataTable CreateDataSource()
   {
       DataTable dataTable = new DataTable();
       dataTable.Columns.Add(new DataColumn("ID", typeof(string)));
       dataTable.Columns.Add(new DataColumn("Name", typeof(string)));
       DataRow dr = dataTable.NewRow();
       dr["ID"] = "0";
       dr["Name"] = "SELECT NAME";
       dataTable.Rows.Add(dr);
       DataRow dr1 = dataTable.NewRow();
       dr1["ID"] = "1";
       dr1["Name"] = "Name1";
       dataTable.Rows.Add(dr1);
       DataRow dr2 = dataTable.NewRow();
       dr2["ID"] = "2";
       dr2["Name"] = "Name2";
       dataTable.Rows.Add(dr2);
       DataRow dr3 = dataTable.NewRow();
       dr3["ID"] = "3";
       dr3["Name"] = "Name3";
       dataTable.Rows.Add(dr3);
       return dataTable;
   }

Thanks,
Shinu.
0
Ali
Top achievements
Rank 1
answered on 05 Apr 2011, 02:50 PM
Thank Shinu for your prompt response. It resolved my issue.

I have another question if you can assist me with. The whole idea of using RadListbox is to give provide multiselect that cannot be achieved using ASP.NET Dropdownlist. The issue I'm facing is that I would like the RadListbox appearance to be like Dropdonwlist control so the user can click on arrow and see the all the items (instead of scrollbar)  and select what they want.

Is this achievable with RadListbox.

Thank you once again.

Ali.
0
Shinu
Top achievements
Rank 2
answered on 06 Apr 2011, 06:53 AM
Hello Ali,

You can use RadComboBox which allows you to select multiple Items.

Take a look at the following demo which explains more on this functionality.
ComboBox / Templates

Thanks,
Shinu.
Tags
ComboBox
Asked by
Ali
Top achievements
Rank 1
Answers by
Shinu
Top achievements
Rank 2
Ali
Top achievements
Rank 1
Share this question
or