Some simple browsing gives this result at MSDN:
GridView Examples for ASP.NET 2.0[
^]
One option is to use the
RowFilter
property of the
DataView
.
You don't give much information about your implementation, so I have to guess here.
DataTable dt = new DataTable();
dt.Columns.Add("date", typeof(DateTime));
dt.Rows.Add(new DateTime(2014, 09, 01));
dt.Rows.Add(new DateTime(2014, 10, 01));
dt.Rows.Add(new DateTime(2014, 10, 11));
dt.Rows.Add(new DateTime(2014, 11, 01));
dt.Rows.Add(new DateTime(2014, 11, 04));
dt.Rows.Add(new DateTime(2014, 11, 30));
dt.Rows.Add(new DateTime(2014, 12, 01));
DateTime date = DateTime.Now;
DataView dv = dt.DefaultView;
int month = 10;
int endDay = 0;
switch (month)
{
case 2: endDay = 28; break;
case 4: endDay = 30; break;
case 6: endDay = 30; break;
case 9: endDay = 30; break;
case 11: endDay = 30; break;
default: endDay = 31; break;
}
DateTime startDate = new DateTime(DateTime.Now.Year, month, 1);
DateTime endDate = new DateTime(DateTime.Now.Year, month, endDay);
dv.RowFilter = String.Format("date >= '{0}' AND date <= '{1}'", startDate, endDate);
Another, and maybe better option, would be to send a new request to the database when a new month is selected.
Then you use the WHERE clause in the SELECT statement.
I am not so good at SQL, so I leave that part to you.
One place to start with SQL is here:
w3schools: SQL Tutorial[
^]
Especially
The SQL WHERE Clause[
^]
Using the creation of startDate and endDate from the code above you can try the code below.
string sqlCommand = String.Format(@"SELECT [column1], [column2] FROM [table] WHERE Date BETWEEN '{0}' AND '{1}'", startDate.ToString("MM/dd/yyyy"), endDate.ToString("MM/dd/yyyy"));
As this code is in c#, you might want to look at the links below in order to convert to VB.
The difference should be minimal.
String.Format Method[
^]
and
http://msdn.microsoft.com/en-us/library/system.string.format(v=vs.110).aspx[
^]
Someone else can probably show you a better SQL query.