简体   繁体   English

从绑定的 combobox 获取数据

[英]Get the data from bound combobox

I m facing problem to get value of combobox which is bound from database我在获取从数据库绑定的 combobox 的值时遇到问题

 `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.SelectedItem.ToString(); string intr = cmbTypeofList.SelectedValue.ToString(); in the both above conditions im getting the selected value as System.Data.DataRowView在上述两种情况下,我将所选值设为 System.Data.DataRowView

string intr = cmbTypeofList.SelectedText; if im giving the above way im getting "" null value如果我以上述方式获得“” null 值

How to get the selected value of the combobox in C# windowsapp如何在C# windowsapp中获取combobox的选定值

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将 combobox 的显示成员和值成员设置为适当的字段名称查看此链接How to set values into ComboBox Items

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM