错误:DropdownList返回'System.Data.DataRowView'作为所选项目的文本值
本文关键字:选项 项目 文本 Data DropdownList 返回 System DataRowView 错误 | 更新日期: 2023-09-27 18:10:05
我有一个下拉列表,其中有所有银行的名称。我想在数据网格视图中显示信用额度。但是下拉列表返回的是system。data。DataRowView'作为所选项目的值。
代码如下:
private void cbxBank_SelectedIndexChanged(object sender, EventArgs e)
{
int i = cbxBank.SelectedIndex;
string bank = cbxBank.Text;
if (i != -1)
{
// this Function Returns the Table of CreditLimit According to Bank Name
DataTable CreditLimit = AM.ReturnAvailableCreditLimit(bank);
//this function just displays the table in Datat Grid View
DataGridViewDisplayDetails(CreditLimit);
}
}
下拉列表中添加数据的代码
Bank = DbRdRw.SqlDbRead("Select BankName from BankMaster", "BankMaster");
cbxBank.DataSource = Bank;
cbxBank.ValueMember = "BankName";
cbxBank.DisplayMember = "BankName";
//ends
您需要指定
对于WinForm,您需要在定义属性后指定数据源,如
Bank = DbRdRw.SqlDbRead("Select BankName from BankMaster", "BankMaster");
cbxBank.ValueMember = "BankName";
cbxBank.DisplayMember = "BankName";
cbxBank.DataSource = Bank; //here
ASP。净
cbxBank.DataSource = ....;//specify your datasource
cbxBank.DataValueField = "BankID";
cbxBank.DataTextField = "BankName";
cbxBank.DataBind();
你有两个选择
- 覆盖你的对象的。tostring()方法,显示你需要的
- 使用下拉列表的DisplayMemberPath(或等效)属性,显示所需的属性