Last post Oct 22, 2008 12:03 PM by hans_v
Oct 17, 2008 10:48 AM|drocco|LINK
I have a GridView being used to display a list of events. The list of events are stored in an AccessDataSource.
On Page_Load I want the GridView to display all records where the month of my field _DATE is = to the current month being displayed on my Calendar control
This would also have to distinguish between years because when the calendar is on October 2008, I would only want to see events from October 2008
The field _DATE is in short date format M/d/yyyy
Could anyone provide some sample code for how I can accomplish this?
Thanks in advance for any helpful replies
Oct 17, 2008 01:17 PM|drocco|LINK
eventsADS1.SelectCommand = "SELECT * FROM [events] WHERE MONTH(_DATE) = #" + eventCalendar.TodaysDate.Month + "#"
This gets the error
Oct 17, 2008 07:36 PM|hans_v|LINK
Oct 20, 2008 04:35 PM|drocco|LINK
Actually this isn't what I want
I don't want it to go by the SelectedDate on the Calendar
When the Calendar loads and its in August, I want all events for August to be listed
If the user changes the month to November I want all events for November to be listed
Oct 20, 2008 07:07 PM|hans_v|LINK
PropertyName="VisibleDate" instead of PropertyName="SelectedDate"
Oct 22, 2008 09:57 AM|drocco|LINK
This is still not doing the job
The GridView is returning 0 records
Oct 22, 2008 11:29 AM|hans_v|LINK
I just tested it, and it works fine. Can you show me your Source code?
Oct 22, 2008 11:33 AM|drocco|LINK
I got it using HiddenFields and not using a SelectParameter at all
If Not IsPostBack Then
eventCalendar.VisibleDate = Today
monthHF.Value = eventCalendar.VisibleDate.Month
yearHF.Value = eventCalendar.VisibleDate.Year
If eventCalendar.SelectedDate = Nothing Then
eventsADS1.SelectCommand = "SELECT * FROM [events] WHERE MONTH([_DATE]) = " + monthHF.Value + " AND YEAR([_DATE]) = " + yearHF.Value + " ORDER BY [_DATE]"
eventsADS1.SelectCommand = "SELECT * FROM [events] WHERE [_DATE] = #" + eventCalendar.SelectedDate + "#"
Then on VisibleMonthChanged()
monthHF.Value = e.NewDate.Month
yearHF.Value = e.NewDate.Year
Oct 22, 2008 12:03 PM|hans_v|LINK
Ýou don't need to code anything, everything can be done in the HTML markup!
<asp:Calendar ID="Calendar1" runat="server" />
<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="true" DataSourceID="eventsADS1">
<asp:AccessDataSource ID="AccessDataSource1" runat="server" DataFile="~/App_Data/databasename.mdb"
SelectCommand="SELECT * FROM [events] WHERE month([_Date]) = month(@SelectedDate) AND year([_Date]) = year(@SelectedDate)">
<asp:ControlParameter ControlID="EventCalendar" DefaultValue="" Name="SelectedDate" PropertyName="VisibleDate" Type="DateTime" />