无法将“iShopClient.iShop.ProductOption”类型的对象强制转换为“System.Data.DataRowView”。 [英] Unable to cast object of type 'iShopClient.iShop.ProductOption' to type 'System.Data.DataRowView'.

查看:72
本文介绍了无法将“iShopClient.iShop.ProductOption”类型的对象强制转换为“System.Data.DataRowView”。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

基本上我有以下错误:



无法将'iShopClient.iShop.ProductOption'类型的对象强制转换为'System.Data.DataRowView'。



我不知道怎么解决这个问题。



我基本上我想要的信息在要传递到其他页面的当前行上。但我甚至无法获得DataRowView的值。帮助将不胜感激















 private void orderButton_Click(object sender,RoutedEventArgs e)
{
if(productOptionsDataGrid.SelectedItem) != null)
{
int productOptionID = Convert.ToInt32(((DataRowView)productOptionsDataGrid.SelectedValue)[OptionID]);
Convert.ToInt32(((DataRowView)productOptionsDataGrid.SelectedValue)[OptionID]);
//productsDataGrid.SelectedItem
// DataRowView drv =(DataRowView)productOptionsDataGrid.SelectedItem;
DataRowView drv2 =(DataRowView)productsDataGrid.SelectedItem;

int productID = Convert.ToInt32(drv2 [ProductID]);
}
else if(productOptionsDataGrid.SelectedItem == null)
{
DataRowView drv2 =(DataRowView)productsDataGrid.SelectedItem;
int productID = Convert.ToInt32(drv2 [ProductID]);
GlobalVariables.productID = productID;
}
}

解决方案

尝试如下

< pre lang =c#> ProductOption po =(ProductOption)productsDataGrid.SelectedItem;
// po.ProductID



似乎你绑定 iShopClient.iShop.ProductOption 对象为 productsDataGrid 数据源。如果绑定数据表,你可以选择项目 DataRowView


Basically I have the following error:

"Unable to cast object of type 'iShopClient.iShop.ProductOption' to type 'System.Data.DataRowView'."

I'm not sure how to get around this.

I basically i want the information on a current row to be passed to a different page. But I cant even get the values of a DataRowView. Help would be appreciated







private void orderButton_Click(object sender, RoutedEventArgs e)
{
    if (productOptionsDataGrid.SelectedItem != null)
    {
        int productOptionID = Convert.ToInt32(((DataRowView)productOptionsDataGrid.SelectedValue)["OptionID"]);
        Convert.ToInt32(((DataRowView)productOptionsDataGrid.SelectedValue)["OptionID"]);
        //productsDataGrid.SelectedItem
        //DataRowView drv = (DataRowView)productOptionsDataGrid.SelectedItem;
        DataRowView drv2 = (DataRowView)productsDataGrid.SelectedItem;

        int productID = Convert.ToInt32(drv2["ProductID"]);
    }
    else if (productOptionsDataGrid.SelectedItem == null)
    {
        DataRowView drv2 = (DataRowView)productsDataGrid.SelectedItem;
        int productID = Convert.ToInt32(drv2["ProductID"]);
        GlobalVariables.productID = productID;
    }
}

解决方案

try like below

ProductOption po= (ProductOption)productsDataGrid.SelectedItem;
//po.ProductID


it seems you binding iShopClient.iShop.ProductOption objects as productsDataGrid Data Source. you can cas't selected item to DataRowView in case of binding with datatable.


这篇关于无法将“iShopClient.iShop.ProductOption”类型的对象强制转换为“System.Data.DataRowView”。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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