本文介绍了无法将“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; } } 解决方案 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 appreciatedprivate 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; }} 解决方案 这篇关于无法将“iShopClient.iShop.ProductOption”类型的对象强制转换为“System.Data.DataRowView”。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 10-23 09:00