无法转换 'System.Data.DataRowView' 类型的对象输入 'System.IConvertible' [英] Unable to cast object of type 'System.Data.DataRowView' to type 'System.IConvertible'

查看:43
本文介绍了无法转换 '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.

这篇关于无法转换 'System.Data.DataRowView' 类型的对象输入 'System.IConvertible'的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆