Click here to Skip to main content
15,883,705 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
When I was Using SelectIndexchanged Property In Combobox i got error here
SSettingsEntity entity = facade.Get_CashPrefix(Convert.ToInt32(cmbSettings.SelectedValue));



Unable to cast object of type 'System.Data.DataRowView' to type 'System.IConvertible'.
Posted

1 solution

Refer - Unable to cast object of type 'System.Data.DataRowView' to type 'System.IConvertible'[^].
Quote:
It looks like your ddlDivisionId.SelectedValue is returning a DataRowView. I assume you bound a DataTable or similar to your dropdown list (assuming that is what we are looking at).

In this case you will need to treat the ddlDivisionId.SelectedValue as a DataRowView (probably casting to that object first) to get the value out of it... I assume something like:

C#
int i = Convert.ToInt32(((DataRowView)ddlDivisionId.SelectedValue)["id"]);

Here you should replace "id" with whatever the name of your field is in your datatable that you want to get out as an integer.

So, instead of doing like below...
C#
Convert.ToInt32(cmbSettings.SelectedValue)

do something like below...
C#
Convert.ToInt32(((DataRowView)cmbSettings.SelectedValue)["id"]);

Here id is the field you want to read.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900