Reputation: 766
I have a Dropdown list in which I have all the banks names. I want to display the credit limit in a Data Grid View. But the Dropdown list is returning 'System.Data.DataRowView' as value of Selected Item.
Here is the code:
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);
}
}
Code to Add Data in DropdownList
Bank = DbRdRw.SqlDbRead("Select BankName from BankMaster", "BankMaster");
cbxBank.DataSource = Bank;
cbxBank.ValueMember = "BankName";
cbxBank.DisplayMember = "BankName";
//ends
Upvotes: 2
Views: 6452
Reputation: 223207
You need to specify
For WinForm You need to specify the DataSource after defining the properties like:
Bank = DbRdRw.SqlDbRead("Select BankName from BankMaster", "BankMaster");
cbxBank.ValueMember = "BankName";
cbxBank.DisplayMember = "BankName";
cbxBank.DataSource = Bank; //here
For ASP.Net
cbxBank.DataSource = ....;//specify your datasource
cbxBank.DataValueField = "BankID";
cbxBank.DataTextField = "BankName";
cbxBank.DataBind();
Upvotes: 6
Reputation: 2629
You have 2 options.
Upvotes: 0