Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
How do I add record to the combo box ?
Message
General information
Forum:
ASP.NET
Category:
Other
Miscellaneous
Thread ID:
00816851
Message ID:
00816918
Views:
18
Hi Winan,

You need set the DataTextField and DataValueField properties for the DropDownList in your BindComboBox method. The DataTextField property is used to tell the DropDownList which column to display from your DataTable. The DataValueField is used to tell the DropDownList which column to save to another DataTable.
Me.ComboUserGroup.DataTextField = "MyDisplayField"
Me.ComboUserGroup.DataValueField = "MyFieldToSave"
>Dear The Expert,
>How do I add record to the combo box ? .. I wrote below codes for add record to the combobox and
>then display them .. but it does not work .. am I missing something?
>
>Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
> If Not IsPostBack Then
> Dim ds As DataSet = GetDataSet()
> BindComboBox(ds)
> End If
>End Sub
>
>
>
>Private Function GetDataSet() As DataSet
> Dim mSQL As String
> mSQL = "Select * from MyUserGroup Order by GroupID"
> Dim con As New OleDbConnection(mConnectionString)
> Dim cmd As New OleDbCommand(mSQL, con)
> Dim adapter As New OleDbDataAdapter(cmd)
> Dim dsGroup As New DataSet()
> adapter.Fill(dsGroup, "UserGroup")
> con.Close()
> Return dsGroup
>End Function
>
>Private Sub BindComboBox(ByVal ds As DataSet)
> ComboUserGroup.DataSource = ds.Tables("UserGroup")
> Me.DataBind()
>End Sub
>
>TIA
>
>Winan
-----------------------------------------

Cathi Gero, CPA
Prenia Software & Consulting Services
Microsoft C# / .NET MVP
Mere Mortals for .NET MVP
cgero@prenia.com
www.prenia.com
Weblog: blogs.prenia.com/cathi
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform