Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

c#

.net

windows

I m using in C# Code

int i = Convert.ToInt32(ddlDivisionId.SelectedValue);

at that time this type of error accrued..

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

how can i solve it ?

Please help

like image 985
forum Avatar asked Oct 14 '25 09:10

forum


2 Answers

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:

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.

like image 52
Chris Avatar answered Oct 16 '25 21:10

Chris


int i = Convert.ToInt32(ddlDivisionId.SelectedValue.ToString());

add .ToString in last it will work

like image 36
malik saifullah Avatar answered Oct 16 '25 21:10

malik saifullah