Dyanamic Data Binding

4 posts, 1 answers
  1. Ali
    Ali avatar
    2 posts
    Member since:
    Apr 2011

    Posted 04 Apr 2011 Link to this post

    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.
  2. Answer
    Shinu
    Shinu avatar
    17764 posts
    Member since:
    Mar 2007

    Posted 05 Apr 2011 Link to this post

    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.
  3. Ali
    Ali avatar
    2 posts
    Member since:
    Apr 2011

    Posted 05 Apr 2011 Link to this post

    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.
  4. Shinu
    Shinu avatar
    17764 posts
    Member since:
    Mar 2007

    Posted 06 Apr 2011 Link to this post

    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.
Back to Top