我有2个gridview看起来像这样: 和2个控制器用于那些gridview:
Gridview控制器1:
[DataObjectMethod(DataObjectMethodType.Select, false)]
public List<OutstandingOrderInfo> OrderInfo()
{
using (var context = new eToolsContext())
{
var data2 = from po in context.PurchaseOrders
where !po.Closed
select new OutstandingOrderInfo()
{
Order = po.PurchaseOrderID,
Date = po.OrderDate,
VendorName = po.Vendor.VendorName,
ContactPhone = po.Vendor.Phone
};
return data2.ToList();
}
}
GridView2控制器
[DataObjectMethod(DataObjectMethodType.Select,false)]
public OrderDetail GetOrderDetail (int purchaseOrderID)
{
using (var context = new eToolsContext())
{
var data = from pod in context.PurchaseOrderDetails
where pod.PurchaseOrderID == purchaseOrderID
select new OrderDetail()
{
StockItemID = pod.StockItemID,
Description = pod.StockItem.Description,
QuantityOnOrder = pod.StockItem.QuantityOnOrder,
};
return data.FirstOrDefault();
}
}
每当单击ViewOrder链接按钮时,我试图将Gridview1中的Order boundfield的值传递给Gridview 2的控制器作为参数。 但我收到的错误是我传递的数据为空。我究竟做错了什么? 这是我处理点击事件的代码:
protected void GridView1_SelectedIndexChanged(object sender, GridViewSelectEventArgs e)
{
e.Cancel = true; // to prevent any other processing in the GridView's default Select handling
GridView sendingGridView = sender as GridView; // notice the safe casting
GridViewRow row = sendingGridView.Rows[e.NewSelectedIndex];
var orderID = row.FindControl("Order") as Label;
int puchaseOrderID = int.Parse(orderID.Text);
GetOrderDetail(puchaseOrderID);
}
private void GetOrderDetail(int purchaseOrderID)
{
var controller = new ReceivingController();
var data = controller.GetOrderDetail(purchaseOrderID);
GridView2.DataSource = data.OrderDetail;
GridView2.DataBind();
}