我有一个下拉列表,其中包含所有银行名称。我想在数据网格视图中显示信用额度。但Dropdown列表返回'System.Data.DataRowView'作为Selected Item的值。
以下是代码:
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);
}
}
在DropdownList中添加数据的代码
Bank = DbRdRw.SqlDbRead("Select BankName from BankMaster", "BankMaster");
cbxBank.DataSource = Bank;
cbxBank.ValueMember = "BankName";
cbxBank.DisplayMember = "BankName";
//ends
答案 0 :(得分:5)
您需要指定
对于WinForm您需要在定义以下属性后指定DataSource:
Bank = DbRdRw.SqlDbRead("Select BankName from BankMaster", "BankMaster");
cbxBank.ValueMember = "BankName";
cbxBank.DisplayMember = "BankName";
cbxBank.DataSource = Bank; //here
对于ASP.Net
cbxBank.DataSource = ....;//specify your datasource
cbxBank.DataValueField = "BankID";
cbxBank.DataTextField = "BankName";
cbxBank.DataBind();
答案 1 :(得分:0)
您有2个选项。