无法转换 'System.Data.DataRowView' 类型的对象输入 'System.IConvertible'
我在 C# 代码中使用
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'
我该如何解决?
请帮忙
看起来您的 ddlDivisionId.SelectedValue
正在返回一个 DataRowView
.我假设您绑定了一个 DataTable 或类似于您的下拉列表(假设这就是我们正在查看的内容).
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).
在这种情况下,您需要将 ddlDivisionId.SelectedValue
视为 DataRowView(可能首先转换为该对象)以从中获取值...我假设如下:>
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"]);
在这里,您应该将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.