Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium


asp calendar control with gridview

Posted on 2009-12-17
Medium Priority
Last Modified: 2012-05-08
hi, i'm trying to make it so when a date is selected on the calendar it pulls the appropriate data from a table and displays it in a gridview.The Calendar Displays the dates from my database fine and i can get the gridview to display the data as well but cant bind the two together.when i click on a date now i get an error saying 'check the manual that corresponds to your MySQL server version for the right syntax to use near ''22/12/2009 00:00:00' at line 1' and can't seem to get it to work.Here is the code i have
<asp:FormView ID="PropertyForm" runat="server" Width="100%">
                                   <table border="0" align="center" width="100%" class="PropertyTable">
                                        <td align="left">
                                        <asp:Calendar id="Calendar1" runat="server" OnDayRender="CalendarDRender" OnSelectionChanged="Calendar1_SelectionChanged" BorderWidth="1px" NextPrevFormat="FullMonth" BackColor="White" Width="350px" ForeColor="Black" Height="190px" Font-Size="9pt" Font-Names="Verdana" BorderColor="White">
                                        <TodayDayStyle BackColor="#CCCCCC"></TodayDayStyle>
                                        <NextPrevStyle Font-Size="8pt" Font-Bold="True" ForeColor="#333333" VerticalAlign="Bottom"></NextPrevStyle>
                                        <DayHeaderStyle Font-Size="8pt" Font-Bold="True"></DayHeaderStyle>
                                        <SelectedDayStyle ForeColor="White" BackColor="#333399"></SelectedDayStyle>
                                        <TitleStyle Font-Size="12pt" Font-Bold="True" BorderWidth="4px" ForeColor="#333399" BorderColor="Black" BackColor="White"></TitleStyle>
                                        <OtherMonthDayStyle ForeColor="#999999"></OtherMonthDayStyle>
                               <span class="mainheading">Event Location and Dates</span><br /><br />          
                        <asp:GridView ID="CalendarList" runat="server" width="450px" AutoGenerateColumns="False" CssClass="gridtable" CellPadding="5" BorderColor="#ff3300" BorderWidth="1px" BackColor="#FFFFFF" >
                        <AlternatingRowStyle BackColor="#F8F8F8" />
                                <asp:TemplateField HeaderText="EventLocation" HeaderStyle-CssClass="gridheading" >
                                    <asp:TemplateField HeaderText="EventDate" HeaderStyle-CssClass="gridheading" >
and the cs file is

protected void Calendar1_SelectionChanged(object sender, System.EventArgs e)
        Calendar Calendar1 = (Calendar)PropertyForm.FindControl("Calendar1");
        string connCalendarString = ConfigurationManager.AppSettings["THConnectionString"];
        MySqlConnection cnxCalendar = new MySqlConnection(connCalendarString);
        MySqlDataAdapter adapterCalendar = new MySqlDataAdapter();
        string cmdCalendarText = "SELECT EventLocation, EventDate FROM eventstable WHERE EventDate='" + Calendar1.SelectedDate.ToString();
        MySqlCommand cmdCalendar = new MySqlCommand(cmdCalendarText, cnxCalendar);
        DataSet dsCalendar = new DataSet();
        adapterCalendar.SelectCommand = cmdCalendar;
        GridView CalendarList = (GridView)PropertyForm.FindControl("CalendarList");
        CalendarList.DataSource = dsCalendar;

        adapterCalendar.Fill(dsCalendar, "CalendarList");

        if (dsCalendar.Tables[0].Rows.Count == 0)
            CalendarList.Visible = false;
            CalendarList.Visible = true;
            CalendarList.DataSource = dsCalendar;
Question by:chrispaton
LVL 42

Accepted Solution

Meir Rivkin earned 2000 total points
ID: 26071545
string cmdCalendarText = "SELECT EventLocation, EventDate FROM eventstable WHERE EventDate='" + Calendar1.SelectedDate.ToString();


string cmdCalendarText = string.Format("SELECT EventLocation, EventDate FROM eventstable WHERE EventDate='{0}'", Calendar1.SelectedDate.ToString());

Author Comment

ID: 26071566
Thanks sedgewick that has fixed the datetime error but my gridview is not displaying data when a date is selected

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In order to hide the "ugly" records selectors (triangles) in the rowheaders, here are some suggestions. Microsoft doesn't have a direct method/property to do it. You can only hide the rowheader column. First solution, the easy way The first sol…
Hello there! As a developer I have modified and refactored the unit tests which was written by fellow developers in the past. On the course, I have gone through various misconceptions and technical challenges when it comes to implementation. I would…
Whether it be Exchange Server Crash Issues, Dirty Shutdown Errors or Failed to mount error, Stellar Phoenix Mailbox Exchange Recovery has always got your back. With the help of its easy to understand user interface and 3 simple steps recovery proced…
Enter Foreign and Special Characters Enter characters you can't find on a keyboard using its ASCII code ... and learn how to make a handy reference for yourself using Excel ~ Use these codes in any Windows application! ... whether it is a Micr…
Suggested Courses

564 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question