无法将“iShopClient.iShop.ProductOption”类型的对象强制转换为“System.Data.DataRowView”。 [英] Unable to cast object of type 'iShopClient.iShop.ProductOption' to type '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 bindingiShopClient.iShop.ProductOption
objects asproductsDataGrid
Data Source. you can cas't selected item toDataRowView
in case of binding with datatable.
这篇关于无法将“iShopClient.iShop.ProductOption”类型的对象强制转换为“System.Data.DataRowView”。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!