I want to Get the Database ID of the item selectd in the Combo box in silverlight either by using SelectedValuePath or by any other way.
Please suggest.
In XAML you must to write de name your Id in the combobox:
SelectedValuePath="ID"
where "ID" is the name of your field.
To get the selected value in c#:
int id=(int)myComboBox.SelectedValue;
Related
I have employee_ID in combo box list. On change of the e_ID I want the selected value to be show in the name and address field using VBA Access code.
How can I get this?
My program uses a database in access which consists of BreedID and BreedName. I have a dropdown box in vb.net which shows the name for the user to select, however in my code I would like to store the ID related to that name so that I can send it over to the access database using oledb. Currently this is what it looks like:
Dim BrVar As String = Breed.SelectedItem.Text
But that isn't working! Please help!
You can add hidden columns to your dropdown box, it may already exist. The first column in a dropdown box is column(0) and you can set the width to 0cm. This can be for the ID value. Leaving column(1) for the Name value.
Then you can use Breed.SelectedItem.column(0)
The first thing to do is on the Data tab set up your rowsource to SELECT both the BreedID and BreedName fields (in that order). Then make sure bound column is set to 1.
Then on the Format tab set Column Count to 2 and Column Widths to 0;1.
That will have the result of displaying the BreedName field but using the BreedID field as the value of the combo box.
Use Dim BrVar As Long = Breed.SelectedItem to get the value of BreedID.
I have a Dialog which has a ComboBox (aComboBox, say) with the following properties set:
DataSource linked to a BindingSource which is linked to an SQL table
DisplayMember linked to a column in that table which is of type String
Here is a pic of how the properties are set:
I want the String value of the item selected in the combo box but I am getting System.Data.DataRowViewwhen I use this code at run time:
aComboBox.SelectedItem.ToString()
How do I get the String value?
Do not use aComboBox.SelectedItem.ToString()
Instead of that Use : aComboBox.SelectedValue()
I managed to fix this by setting the Value Member attribute as shown in the following image, I am then able to retrieve the String value by calling aComboBox.SelectedValue.ToString() :
Note: Before, I only had the Display Member attribute set.
I would like to populate a drop down list using values from the database. I would like to know how I can add to the dropdown list both the display member and value member straight all from the database
Display Name: Account_Name
Member Value: Account_ID
Is this possible? If yes, How is it done
Assuming you are binding programatically using a datatable/datareader or similar. Use the DataTextField and DataValueField Properties. e.g.
DropDownList.DataValueField = "Account_ID"
DropDownList.DataTextField = "Account_Name"
EDIT
For a combo box with a datareader you would use something akin to the following
YourComboBox.DataSource = yourDataReader
YourComboBox.ValueMember = "Account_ID"
YourComboBox.DisplayMember = "Account_Name"
I am quite new to programming and will really appreciate if anyone can help me..Thanks
Question: My dropdown list in my web project is holding value of a person name in 'DataTextField' and it is holding person's ID in the 'DataValueField'
so if I want to print the value of the DataValueField what shall I do?
What I did:
Dim PersonID as String = DropDownPerson.DataValueField
Response.Write(PersonID)
but the above code is returning the column name and not the value of the column.
Please help !
Dim PersonID as String = DropDownPerson.SelectedValue
Just to clear something up - DataTextField and DataValueField are used by the dropdown control (and databinding) to describe which fields to use as the display value and identity value for a selected row.
SelectedValue holds the actual value of the field named in DataValueField for the selected row.