Hi,
I am having gridview which is binded to the linq query as folllowing
Public Overridable Function getInventoryWorksheet(ByVal OrderDetailspredicates As List(Of Expression(Of Func(Of Order_Detail, Boolean))), _
Optional ByVal Productpredicates As List(Of Expression(Of Func(Of Product, Boolean))) = Nothing) As IQueryable
' These predicates will build the where condition for the query at run time
Dim OrderDetailspredicate = PredicateBuilder.True(Of Order_Detail)()
Dim Productpredicate = PredicateBuilder.True(Of Product)()
' Combine the predicates by And
Productpredicate = PredicateBuilder.CombinePredicates_And(Productpredicates)
OrderDetailspredicate = PredicateBuilder.CombinePredicates_And(OrderDetailspredicates)
Dim db = New MyLinQDatabaseDataContext
Dim orderDetails = From current In db.Order_Details.Where(OrderDetailspredicate)
Dim groups = From mygroup In orderDetails.GroupBy(Function(group As Order_Detail) group.ItemID) Select New With _
{ _
.ItemID = mygroup.Key, _
.QtyOrdered = mygroup.Sum(Function(group As Order_Detail) group.QTYOrdered), _
.QtyShipped = mygroup.Sum(Function(group As Order_Detail) group.QtyShiped) _
}
' Dim result = groups.Join(
Dim groupdata = (From OD In groups Join Products In db.Products.Where(Productpredicate) On OD.ItemID Equals Products.SKU).DefaultIfEmpty
'Dim datatable = groupdata.ToADOTable()
'Dim stil = From testt In groupdata Select
Return groupdata End Function
So my groupdata is Iquerable of two objects OD {ItemID,QtyOrdered,QtyShipped} and a complete Products object.I want to databind the gridview to groupdata Please see my code below
<asp:GridView ID="GvInventoryWorkSheet" AllowPaging="false" AllowSorting="True" width="800px"
PageSize="20" AutoGenerateColumns="False"
runat="server" CellPadding="4" ForeColor="#333333" GridLines="None" >
<FooterStyle BackColor="#5D7B9D" Font-Bold="True" ForeColor="White" />
<PagerStyle CssClass="PagerStyle" />
<PagerSettings PageButtonCount="5" Position="TopAndBottom" Mode="NumericFirstLast" FirstPageText="First" LastPageText="Last" />
<RowStyle CssClass="customerListNormal" BackColor="#F7F6F3"
ForeColor="#333333" />
<Columns>
<asp:TemplateField>
<ItemTemplate>
<asp:CheckBox ID="aspxCBX" ToolTip='<%# DataBinder.Eval(Container.DataItem, "OD.ItemID") %>' runat="server" />
</ItemTemplate>
</asp:TemplateField>
<asp:BoundField ItemStyle-Width="80px" HeaderText="Item No." DataField="OD.ItemID" SortExpression="OD.ItemID" />
<asp:BoundField ItemStyle-Width="80px" HeaderText="SKU" DataField="Products.SKU" SortExpression="Products.SKU" />
</Columns>
<PagerStyle CssClass="GvPagerRow" />
<SelectedRowStyle BackColor="#E2DED6" Font-Bold="True" ForeColor="#333333" />
<HeaderStyle CssClass="GvHeader" />
<EditRowStyle BackColor="#999999" />
<AlternatingRowStyle CssClass="customerlistAlternate" BackColor="White"
ForeColor="#284775" />
</asp:GridView>
But it say OD.ItemID is not a dataItem of the datasource. Can anybody tell me how can I acheive this functionality.
Thank,
Syed