我有一个网格视图,其中包含过去,现在和将来的日期。页面加载时如何将其设置为从今天或更近的日期开始显示,并且仍然可以访问过去和将来的日期?
我的.aspx文件中有这个
<asp:GridView ID="GridView1" runat="server" ItemType="XXXXX.Models.YYYYY" DataKeyNames="YYYYYID"
SelectMethod="YYYYYGrid_GetData" UpdateMethod="YYYYYGrid_UpdateItem"
AutoGenerateColumns="false" AllowSorting="true" AllowPaging="true"
...
<Columns>
...
<asp:TemplateField HeaderText="Date" SortExpression="YYYYYDateTime">
<ItemTemplate>
<asp:Label Text="<%# Item.YYYYYDateTime.Value.ToShortDateString()%>"
runat="server" />
</ItemTemplate>
</asp:TemplateField>
...
</Columns>
...
</asp:GridView>
以下是获取数据的代码
public IQueryable<YYYYY> YYYYYGrid_GetData([Control] YYYYY._SSSSS? displaySSSSS)
{
XXXXXContext db = new XXXXXContext();
int id = int.Parse(Session["DDDDDID"].ToString());
var query = db.YYYYY.Where(p => p.DDDDDID == id).Include(p => p.PPPPP);
if (displaySSSSS != null)
{
query = query.Where(s => s.SSSSS == displaySSSSS);
}
return query;
}
目标输出示例:
Data from Database:
-----------------
Date | Data
03/01/15 | AA
03/02/15 | BB
04/01/16 | CC
04/03/16 | DD
04/05/16 | EE
Gridview on Page load:
-----------------
Date | Data
04/03/16 | DD <-- eg. date today
04/05/16 | EE
page 2
Navigate gridview to page 1 to show past dates:
---------------
Date | Data
03/01/15 | AA
03/02/15 | BB
04/01/16 | CC