Search code examples
c#linqdata-bindingjcomboboxext.net

Binding Combobox


I am developing a web application with Ext.Net.

How can I bind combobox from database?

This is my query:

dynamic getRegions = (
    from region in db.Regions 
    orderby region.RgnName 
    select region.RgnName);

Solution

  • Just out of interests sake, here's another quick <ext:ComboBox> sample which demonstrates adding data to the ComboBox without using an <ext:Store>. Basically the same technique as using an <asp:DropDownList> and adding ListItem objects.

    Example

    <script runat="server">
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!X.IsAjaxRequest)
            {
                // Add individual Items
                this.ComboBox1.Items.Add(new ListItem("Region1", "England"));
                this.ComboBox1.Items.Add(new ListItem("Region2", "Scotland"));
                this.ComboBox1.Items.Add(new ListItem("Region3", "Wales"));
    
                // AddRange alternative
                // this.ComboBox1.Items.AddRange(new ListItem[] {
                //     new ListItem("Region1", "England"),
                //     new ListItem("Region2", "Scotland"),
                //     new ListItem("Region3", "Wales")
                // });
            }
        }
    </script>
    
    <ext:ComboBox ID="ComboBox1" runat="server" />
    

    Cheers!