Honey
Honey

Reputation: 163

Get the data from bound combobox

I m facing problem to get value of combobox which is bound from database

 `String stri = "Select [Interest] from tbl_Interests";
            SqlCommand command = new SqlCommand(stri, con);
            SqlDataAdapter da = new SqlDataAdapter(command);
            DataSet ds = new DataSet();
            da.Fill(ds,"tbl_Interests");
            cmbTypeofList.DataSource = ds.Tables["tbl_Interests"];
            cmbTypeofList.ValueMember = "Interest";`

calling it string intr = cmbTypeofList.SelectedItem.ToString(); string intr = cmbTypeofList.SelectedValue.ToString(); in the both above conditions i m getting the selected value as System.Data.DataRowView

string intr = cmbTypeofList.SelectedText; if i m giving the above way i m getting "" null value

How to get the selected value of the combobox in C# windowsapp

Upvotes: 0

Views: 287

Answers (1)

DeveloperX
DeveloperX

Reputation: 4683

set the display member and value membr of combobox to appropriate field name Take a look to this link How to set values into ComboBox Items

Upvotes: 1

Related Questions