asp calendar control with gridview

Posted on 2009-12-17
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

    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

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

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Highfive Gives IT Their Time Back

    Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

    Suggested Solutions

    Bit flags and bit flag manipulation is perhaps one of the most underrated strategies in programming, likely because most programmers developing in high-level languages rely too much on the high-level features, and forget about the low-level ones. Th…
    Entity Framework is a powerful tool to help you interact with the DataBase but still doesn't help much when we have a Stored Procedure that returns more than one resultset. The solution takes some of out-of-the-box thinking; read on!
    To add imagery to an HTML email signature, you have two options available to you. You can either add a logo/image by embedding it directly into the signature or hosting it externally and linking to it. The vast majority of email clients display l…
    Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…

    758 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

    Need Help in Real-Time?

    Connect with top rated Experts

    11 Experts available now in Live!

    Get 1:1 Help Now