.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
Sign In
Win Surprise Gifts!!!

Top 5 Contributors of the Month
david stephan
Gaurav Pal
Post New Web Links

Binding value to combobox or dropdown

Posted By:      Posted Date: August 25, 2010    Points: 0   Category :ASP.Net

How can we bind a value to a combobox or dropdown? What is the property for binding a value? 


View Complete Post

More Related Resource Links

Binding an array to dropdown list


I have the following string which is a list of urls. How do I get this to work so the url shows for the selection and also is the value?      


allLinks = newAllLinks
        Me.DropDownList1.DataTextField = "Link"
        Me.DropDownList1.DataValueField = "LinkURL"
        Me.DropDownList1.Items.Insert(0, New ListItem(" - Select - ", 0))
        Me.DropDownList1.DataSource = allLinks


 ArgumentNullException: Value cannot be null.
Parameter name: container]
   System.Web.UI.DataBinder.GetPropertyValue(Object container, String propName) +121
   System.Web.UI.DataBinder.GetPropertyValue(Object container, String propName, String format) +8

TextBox shows binding source text when window load, so why not with the ComboBox?

How can I get a ComboBox to show the binding source value when my window opens?  I have been searching all day for a solution to this, but cannot find anything.  So I have created a sample project to demonstrate my problem.  Below is a Vehicle class, very simple, two members Category and Make.  Category is an enumeration, Make is a string. namespace ComboExample { public class Vehicle { // Constants and enumerations public enum eCategory { Road, Air, Sea } // Attributes public eCategory Category { get; set; } public String Make { get; set; } // Construction public Vehicle(eCategory Category, String strMake) { this.Category = Category; this.Make = strMake; } } } Here is the C# for the MainWindow.  A new Vehicle object is created as a member.  In the constructor I set a data-provider in the XAML to this Vehicle object.  There is a button event for showing the values of the controls and objects so I can check the binding. namespace ComboExample { // Interaction logic for MainWindow.xaml public partial class MainWindow : Window { // Attributes Vehicle m_Car = new Vehicle(Vehicle.eCategory.Road, "BMW"); // Construction public MainWindow() { InitializeComponent(); // link data-p

ajax combobox having problem in binding data

Hi i am using ajaxtoolkit:combobox and i tried to bind data to this control in code behind file. but it is taking 3 to 4 mints to bind data and display the page. what is the problem? I am providing my aspx code and code behind code here<%@ Page Language="C#" MasterPageFile="~/Site.master" AutoEventWireup="true" CodeFile="TestPage.aspx.cs" Inherits="Dashboards_TestPage" Title="Untitled Page" %> <asp:Content ID="Content1" ContentPlaceHolderID="cphMain" Runat="Server"> <asp:ScriptManager runat="server" ID="scriptMgr"> </asp:ScriptManager> <table border="1"> <tr> <td> <ajaxToolkit:ComboBox ID="ddlProgram" runat="server" DropDownStyle="DropDownList" AutoCompleteMode="SuggestAppend" CaseSensitive="False" MaxLength="10"> </ajaxToolkit:ComboBox> </td> </tr> </table> </asp:Content>  Code behind code:public partial class Programs_TestPage : System.Web.UI.Page { ProgramData programData = new ProgramData(); protected void Page_Load(object sender, EventArgs e) { if (!Page.IsPostBack)

binding datetimecontrol,dropdown,textbox inside gridview and update each gridviewrow

i have a web part with datetimecontrol(sharepoint) inside a  gridview. when the page loads this this gridview will be loaded with dtc control and the selecteddate would be one of the columns in the splist.also gridview contaisn dropdowns, textboxes, when an update button cliked inside grid, i need to save the info in the splist.  currently i am not getting the value  bound with dtc control. i am getting blank date inside dtc. though in the  rowdatabound event i amcapturing the values due to some reason i am not able to view the value in the DTCcontrol. can anybody give me help me how to achieve this? any  help links/ sample code.. appreciate the help                         

Element Binding - ComboBox

  <ComboBox Height="23" HorizontalAlignment="Left" Margin="139,59,0,0" Name="comboBox1" VerticalAlignment="Top" Width="120" > <ComboBoxItem Content="Spain"/> <ComboBoxItem Content="England"/> </ComboBox> <ComboBox Height="23" HorizontalAlignment="Left" Margin="139,154,0,0" Name="comboBox2" VerticalAlignment="Top" Width="120" > <ComboBoxItem Content="Madrid"/> <ComboBoxItem Content="Barcelona"/> <ComboBoxItem Content="London"/> <ComboBoxItem Content="Birmingem"/> </ComboBox> I've problem... I want to use element binding, in this source to filter Cities by selected Countries how do it?  

Binding ListBox to ComboBox's SelectedItem

Hi All,   I have a ComboBox that is bound to a collection of People. When the user selects a Person in the ComboBox, I want a ListBox below that to be populated wtih the Person's Friends.   Is it something like:   <ComboBox x:Name="PeopleComboBox" ItemsSource="{Binding People}"/> <ListBox ItemsSource="{Binding ElementName=PeopleComboBox, Path=SelectedItem.Friends}"/>   I'm going for something like that.

Problem whit ComboBox binding in WPF

Here are my main classes: Configuration { List<Environment > EnvironList, Source ConfigSource } Source { List<FileSource > FileSourceList } FileSource {} inherits class     SourceInfo { string Id, string Source } Environment { List<FileDestination > EnvirFileList } FileDestination { List<String> DestinationList } and inherits class     Info { string SourceId } Info .SourceId refers to SourceInfo .Id. Example: Id="mySource" Source="C:\PathToMyFiles" The Configuration is read from an XML file. In my display, I want to gatter all the SourceInfo objects of my Configuration and put them in a comboBox, to be available for selection in the Environment ->FileDestination ->Info .SourceId. So far, no problem. I also want to select the current value. I did that by putting it at the begining of the list and selecting that index when the list is created. The problem I have is when I try to modify the value. When I change the selection, it shows me the new value, but that value is never saved. If I reload the list, the old value is selected. Also, when I add a new File in the  Environment .EnvirFileList, the SourceId is never added to the XML file. That XML file is create with Serialized properties from my classes. If I remove the ComboBox and use a textbox, the value is added to the XML file. Below is

Adding new rows to Datagrid with a Combobox column generate "two-way binding requires path or xpath"



    I have datagrid control with a template combobox column like:

 <DataGridTemplateColumn Header="Fault code" Width="75">
                                    <TextBlock Text="{Binding FaultCode1}" />

autocomplete combobox/textbox binding to dataset


Hi All.

I found sample http://www.codeproject.com/KB/WPF/WPFAutoCompleteTextbox.aspxAutoComplete ComboBox where data is hardcoded in the code. I would like to use AutoComplete ComboBox binded to dataset. I don't have a problem binding data to ComboBox but I have problem if need that combobox autocomplete and filtered listbox. That is bit of code which I found

  Public Sub New()

    textBox1.AddItem(New AutoCompleteEntry("Toyota Camry", "Toyota Camry", "camry", "car", "sedan"))
    textBox1.AddItem(New AutoCompleteEntry("Toyota Corolla", "Toyota Corolla", 

Help binding ComboBox to XML file using c#


I have a ComboBox defined as such (fragment)

<ComboBox Margin="4,0,1,3" Name="ComboBoxGroupSelector" SelectedValuePath="URL" ItemsSource="{Binding}"


and in my code-behind I am trying to bind it this way:


public static XmlDataProvider calendargroupdata = new XmlDataProvider();

                calendargroupdata.Source = new Uri(@newBindingPath, UriKind.RelativeOrAbsolute);
                calendargroupdata.XPath = "/Groups/Group";
                System.Windows.Data.Binding binding = new System.Windows.Data.Binding();
                binding.Source = calendargroupdata;
                binding.XPath = "Description";
                ComboBoxGroupSelector.SetBinding(ItemsControl.ItemsSourceProperty, binding);


Xml file format is like this:

<?xml version="1.0"

combobox selected item value doesnot get updated when binding value changes


i have a combobox  as below






<ComboBox TextSearch.TextPath="Label"

WPF ComboBox Binding problem



I have combobox that is has its itemsource bound to a list returned from DB, as follows




ComboBox Name

How to detect if dropdown of combobox opens above or underneath?


I've got a custom UserControl embedded in a DataGrid. This control consists of a grid with two rows; the first, containing a title (of what the content of the dropdown in the combo box represents) and the second containing the combo box itself.

My problem is, that when the combo box is located somewhere in the lower part of the screen, the popup shows up above the combo box and hides the title. I'd like to detect this and swap rows to show the title underneath the combo box.

What I've tried so far:
I've hoped to be able to get the upper left corner of the (opened) popup and check it against the location of the UserControl itself with following code


    private void cbItems_DropDownOpened(object sender, EventArgs e)
      var popup = (Popup)cbItems.Template.FindName("PART_Popup", cbItems);
      var p = popup.PointToScreen(new Point(0, 0));
      var p2 = this.PointToScreen(new Point(0, 0));

ComboBox : Display selected value with Binding



I have a problem with my ComboBox, it won't show the selected value even if it select it. Items are binded.

Code behind: Me.DataContext = from Miss in myXDoc.<Miss>

Code XAML :





WPF: how can we chang the combobox dropdown box's background with override whole combobox control t


Is there a simply way to can change the Combobox drop down box's background without override whole combobox controltemplate?

the default combobox dropdown box background is white. we like to customize it. thx!



Binding a Collection to a ComboBox


The following is a the class, a list of which I wish to display in a WPF combo box
    public class DivisionItem

        private int _divn_ID = -1;
        private string _divn_Nm = "";
        private int _divn_Mgr = -1;

        private string _addrLn1 =&nb

ComboBox not querying SelectedValuePath when binding initial value


Hi everyone,

I came across this weird problem with a combo box (also tried list box) where its initial value is not set to the requested value based on the property named in SelectedValuePath. In some cases, the combo box is empty initially but it populated its available items correctly, and I can later set the values, etc. Everything works except the initial value.

Here is my combo box declaration:

<ComboBox ItemsSource="{Binding States}" DisplayMemberPath="Function" SelectedValuePath="Value"
     SelectedValue="{Binding Value, Mode=TwoWay, ValidatesOnExceptions=True}"
     MaxWidth="150" Width="150" Grid.Column="1" />

By itself this works perfect. The problem comes when this is combined with another combo box in a different part of the interface which displays items based on the same collection.

The above combo box declaration is used in a popup window that is activated by a toggle button from a tree view item. But I also have a combo box displaying the same set of values in a property grid (although that combo box is populated slightly different due to property grid requirements).

The combo box in the property grid works perfect in every scenario (there is always an initial value). The combo box in the tree view item popup does not show

ASP.NetWindows Application  .NET Framework  C#  VB.Net  ADO.Net  
Sql Server  SharePoint  Silverlight  Others  All   

Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend