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.comwww.prenia.comWeblog: blogs.prenia.com/cathi