troubleshooting Question

Asp calendar with gridview

Avatar of chrispaton
chrispaton asked on
C#ASP.NET
57 Comments1 Solution1360 ViewsLast Modified:
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.i think im missing something to bind the two together but can't see what.I'm not very good at this sort of thing yet.Here is my code
<asp:FormView ID="PropertyForm" runat="server" Width="100%">
                                <ItemTemplate>
                                   <table border="0" align="center" width="100%" class="PropertyTable">
                                    <tr>
                                        <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>
                                        </asp:Calendar>
                               <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" />
                            <Columns>
                                <asp:TemplateField HeaderText="EventLocation" HeaderStyle-CssClass="gridheading" >
                                    </asp:TemplateField>
                                    <asp:TemplateField HeaderText="EventDate" HeaderStyle-CssClass="gridheading" >
                                </asp:TemplateField>
                           </Columns>                                
                        </asp:GridView>
                          </td>
                           </tr>
                             </table>
                              </ItemTemplate>
                               </asp:FormView>
and the cs file
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 = string.Format("SELECT EventLocation, EventDate FROM eventstable WHERE EventDate='{0}'", Calendar1.SelectedDate.ToString());
        MySqlCommand cmdCalendar = new MySqlCommand(cmdCalendarText, cnxCalendar);
        DataSet dsCalendar = new DataSet();
        adapterCalendar.SelectCommand = cmdCalendar;
        adapterCalendar.Fill(dsCalendar);
        GridView CalendarList = (GridView)PropertyForm.FindControl("CalendarList");
        CalendarList.DataSource = dsCalendar;
        CalendarList.DataBind();

        adapterCalendar.Fill(dsCalendar, "eventstable");

        if (dsCalendar.Tables[0].Rows.Count == 0)
        {
            CalendarList.Visible = false;
        }
        else
        {
            CalendarList.Visible = true;
            CalendarList.DataSource = dsCalendar;
            CalendarList.DataBind();
        }
    }
}
Join the community to see this answer!
Join our exclusive community to see this answer & millions of others.
Unlock 1 Answer and 57 Comments.
Join the Community
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 57 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros