From dePoPo.net

Selecting a date range on a gridview

Posted in: ASP.NET
By dePoPo
Sep 24, 2009 - 2:21:26 PM


The ASP.NET gridview is bound to a standard sql selection query, so to select a daterange you can configure the bound SQLDataSource and do something like this:

' --- Select item from the last 7 days
SELECT        id, item_header, item_date, item_cat
FROM           items
WHERE        (item_date >= DATEADD(day, - 7, GETDATE()))
ORDER BY item_date DESC, id DESC

' --- Or a range
SELECT        id, item_header, item_date, item_cat
FROM           items
WHERE        (item_date BETWEEN DATEADD(day, - 14, GETDATE()) AND DATEADD(day, - 7, GETDATE()))
ORDER BY item_date DESC, id DESC



© Copyright 2010 by dePoPo.net