Let's assume we have a Web Service which will return the results as an object for IN and OUT data records.
The following will explain how to use LINQ to query and then bind the results to the asp:DataGrid
C# code:
C# code:
//query to get currunt month data ordered by LOCAL_TIME then TYPE
var thisMonthData = eData.Contents
.OrderByDescending(o => o.LOCAL_TIME)
.OrderByDescending(o2 => o2.TYPE)
.Where(m => m.DATE.Substring(0, 6)
== DateTime.Today.ToString("yyyyMM", arCulture));
//Bind Data
eDataGrid.DataSource = thisMonthData;
eDataGrid.DataBind();
//query to get currunt month data ordered by LOCAL_TIME for TYPE=IN
var thisMonthDataIn = eData.Contents
.OrderByDescending(o => o.LOCAL_TIME)
.Where(r => r.TYPE == "IN")
.Where(m => m.DATE.Substring(0, 6) == DateTime.Today.ToString("yyyyMM", arCulture));
//Bind Data
eINDataGrid.DataSource = thisMonthDataIn;
eINDataGrid.DataBind();
//query to get currunt month data ordered by LOCAL_TIME for TYPE=OUT
var thisMonthDataOut = eData.Contents
.OrderByDescending(o => o.LOCAL_TIME)
.Where(r => r.TYPE == "OUT")
.Where(m => m.DATE.Substring(0, 6) == DateTime.Today.ToString("yyyyMM", arCulture));
//Bind Data
eOUTDataGrid.DataSource = thisMonthDataOut;
eOUTDataGrid.DataBind();
Markup:
<asp:DataGrid CssClass="gvTbl" ID="eINDataGrid" runat="server" AutoGenerateColumns="true">
<HeaderStyle HorizontalAlign="Center" />
<ItemStyle BackColor="#DAF1F2" HorizontalAlign="Right" />
<AlternatingItemStyle BackColor="#ECE9EA" />
<Columns>
</Columns>
</asp:DataGrid>
<asp:DataGrid CssClass="gvTbl" ID="eOUTDataGrid" runat="server" AutoGenerateColumns="true">
<HeaderStyle HorizontalAlign="Center" />
<ItemStyle BackColor="#DAF1F2" HorizontalAlign="Right" />
<AlternatingItemStyle BackColor="#ECE9EA" />
<Columns>
</Columns>
</asp:DataGrid>
<asp:DataGrid CssClass="gvTbl" ID="eDataGrid" runat="server" AutoGenerateColumns="true">
<HeaderStyle HorizontalAlign="Center" />
<ItemStyle BackColor="#DAF1F2" HorizontalAlign="Right" />
<AlternatingItemStyle BackColor="#ECE9EA" />
<Columns>
</Columns>
</asp:DataGrid>