• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1282
  • Last Modified:

Asp calendar with gridview

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();
        }
    }
}
0
chrispaton
Asked:
chrispaton
  • 29
  • 27
1 Solution
 
silemoneCommented:
what part do you know for sure is working...I've never used a dataAdapter the way you did...is this the norm?

i.e. I've always did this with a dataAdapter which uses a SqlCommand...

SqlDataAdapter adapter = new SqlDataAdapter(objSqlCommand);
adapter.Fill(objDS);

because up to the binding, everything looks good...that's the only part i'm personally unsure of...
0
 
chrispatonAuthor Commented:
Hi silemone,
if i ask for the data in the gridview it will display the correct data.by which i mean like this
<ItemTemplate>
<asp:Label ID="StartDate_Label" runat="server" Text='<%# DataBinder.Eval(Container.DataItem, "StartDate", "{0:d}") %>
</ItemTemplate>
but it does'nt seem to be getting anything from the table when i click on a date in the calendar.
not sure how i can bind the two together
0
 
rajeeshmcaCommented:
Hi

check whether are u able to find the grid with

GridView CalendarList = (GridView)PropertyForm.FindControl("CalendarList");
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
chrispatonAuthor Commented:
Hi, yes it finds the gridview control but says 'The name 'CalendarList' does not exist in the current context' on this line
CalendarList.DataSource = dsCalendar;
0
 
chrispatonAuthor Commented:
ok fixed the last problem.now the page loads but it's still not displaying the gridview when i click on a date in the calendar
0
 
rajeeshmcaCommented:
what is the puprose of rebinding the grid view


 adapterCalendar.Fill(dsCalendar, "eventstable");

        if (dsCalendar.Tables[0].Rows.Count == 0)
        {
            CalendarList.Visible = false;
        }
        else
        {
            CalendarList.Visible = true;
            CalendarList.DataSource = dsCalendar;
            CalendarList.DataBind();
        }

Just remove that
0
 
chrispatonAuthor Commented:
ok i have removed it and now have it as

protected void Calendar1_SelectionChanged(object sender, System.EventArgs e)
{
Calendar Calendar1 = (Calendar)PropertyForm.FindControl("Calendar1");
GridView GridView1 = (GridView)PropertyForm.FindControl("CalendarList");
string connCalendarString = ConfigurationManager.AppSettings["THConnectionString"];
MySqlConnection cnxCalendar = new MySqlConnection(connCalendarString);
MySqlDataAdapter adapterCalendar = new MySqlDataAdapter();
string cmdCalendarText = string.Format("SELECT 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, "AllTables");
if (dsCalendar.Tables[0].Rows.Count == 0)
{
CalendarList.Visible = false;
}
else
{
CalendarList.Visible = true;
}
}
}
if i change the line CalendarList.Visible = False   to  true it will display the gridview with all the dates from the table so we know it's binding to the gridview ok.If it's false it displays nothing and should pull the selected date from the table when it is clicked on the calendar
hope this helps
0
 
rajeeshmcaCommented:
Remove this line too. adapterCalendar.Fill(dsCalendar, "AllTables");

Then one more thing, why do you want to make ithe calendarList to visible=false;

Initially it will be Visible=true; only.

But the gridview will not have any data to display. so it wont display anything .

Only during the Calendar1_SelectionChanged event, you will feed the grid (CalendarList) with the Data.

So there is no need to make the grid to visible true or false.
0
 
chrispatonAuthor Commented:
I found the code on an asp.net site and adapted it to suit my needs and it has Visible = False or true so that the gridview only displays information for the date selected on the calendar.I have tried to remove these lines of code and the gridview displays nothing
0
 
chrispatonAuthor Commented:
sorry rajeeshmca if i remove these lines gridview displays all dates from my table and the calendar seems to do nothing to influence it
0
 
rajeeshmcaCommented:
Did you remove all these things

adapterCalendar.Fill(dsCalendar, "AllTables");
if (dsCalendar.Tables[0].Rows.Count == 0)
{
CalendarList.Visible = false;
}
else
{
CalendarList.Visible = true;
}

If it is not displaying anything after removing the above, then give only
CalendarList.Visible = true;  
0
 
chrispatonAuthor Commented:
this is what i have now

protected void Calendar1_SelectionChanged(object sender, System.EventArgs e)
{
Calendar Calendar1 = (Calendar)PropertyForm.FindControl("Calendar1");
GridView GridView1 = (GridView)PropertyForm.FindControl("CalendarList");
string connCalendarString = ConfigurationManager.AppSettings["THConnectionString"];
MySqlConnection cnxCalendar = new MySqlConnection(connCalendarString);
MySqlDataAdapter adapterCalendar = new MySqlDataAdapter();
string cmdCalendarText = string.Format("SELECT 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();
}
}
the gridview is displaying all the dates from my table but the calendar does nothing to change this
0
 
rajeeshmcaCommented:
when you give the other codes which was deleted are u getting the desired result
0
 
chrispatonAuthor Commented:
No i need it so when i click on a date in the calendar it populates the gridview with that date only.as it is the gridview displays every date from my table in the gridview and the calendar does nothing when i click on a date
0
 
rajeeshmcaCommented:
then keep a breakpoint and check what Calendar1.SelectedDate.ToString() is returning. I thing it is not providing the selected date.. Check it out
0
 
chrispatonAuthor Commented:
sorry rajeeshmca i'm not sure how to do this
0
 
rajeeshmcaCommented:
Do like his...

Comment everything within the Calendar_SelectionChanged event... only have

Calendar Calendar1 = (Calendar)PropertyForm.FindControl("Calendar1");
Response.Write("Selected Calendar Date = " + Calendar1.SelectedDate.ToString());

Check what this writing on the form
0
 
chrispatonAuthor Commented:
on the top of my page it displays 'Selected Calendar Date = 30/12/2009 00:00:00' which is the correct date i selected on the calendar
0
 
rajeeshmcaCommented:
so now execute the sql like

SELECT EventDate FROM eventstable WHERE EventDate='30/12/2009 00:00:00'

find what it is returning
0
 
chrispatonAuthor Commented:
Nothing is returned
0
 
rajeeshmcaCommented:
Try with only

SELECT EventDate FROM eventstable WHERE EventDate='30/12/2009'

check whether this returns anything?
0
 
chrispatonAuthor Commented:
still nothing returned
0
 
rajeeshmcaCommented:
Then how is the CalendarList getting bound with all the Dates.

Again just give the following within the selectedChange event

Calendar Calendar1 = (Calendar)PropertyForm.FindControl("Calendar1");
GridView GridView1 = (GridView)PropertyForm.FindControl("CalendarList");
string connCalendarString = ConfigurationManager.AppSettings["THConnectionString"];
MySqlConnection cnxCalendar = new MySqlConnection(connCalendarString);
MySqlDataAdapter adapterCalendar = new MySqlDataAdapter();
string cmdCalendarText = string.Format("SELECT 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);

Response.Write("Count= " + dsCalendar.Tables.count.ToString());


0
 
rajeeshmcaCommented:
see what it is showing
0
 
chrispatonAuthor Commented:
i get this error
'System.Data.DataTableCollection' does not contain a definition for 'count' and no extension method 'count' accepting a first argument of type 'System.Data.DataTableCollection' could be found (are you missing a using directive or an assembly reference?)
 
0
 
rajeeshmcaCommented:
Change count to Count and check it out
0
 
chrispatonAuthor Commented:
Still the same error.already had it as a capital C but error shows it as counts and tried it the other way and it's the same
0
 
chrispatonAuthor Commented:
not sure if it helps but if i have it as
Response.Write("Count= " + dsCalendar.Tables.ToString());
it returns Count= System.Data.DataTableCollection
0
 
chrispatonAuthor Commented:
ok it says Count= 1
0
 
rajeeshmcaCommented:
No that will doesnt help... what was the error it gave when you gave as

Response.Write("Count= " + dsCalendar.Tables.Count.ToString());
0
 
chrispatonAuthor Commented:
sorry my mistake like that it returns Count= 1
0
 
rajeeshmcaCommented:
From where does that table come when no result is provided by the query...
0
 
chrispatonAuthor Commented:
it's a navicat table.don't really understand your question.thanks for being patient but still novice at this
0
 
rajeeshmcaCommented:
when we executed the query

SELECT EventDate FROM eventstable WHERE EventDate='30/12/2009 00:00:00'

It did not return any record.

so how did that dataset get filled with records.. ok leave

check Response.Write("Count= " + dsCalendar.Tables.Rows[0].Count.ToString());
0
 
chrispatonAuthor Commented:
it returns Count= 0 but had to change it to
Response.Write("Count= " + dsCalendar.Tables[0].Rows.Count.ToString());
0
 
rajeeshmcaCommented:
So there is no record in the Table. Then how does the gridview get populated with all dates.
0
 
chrispatonAuthor Commented:
i have a table with two dates in it and already pull dates from it successfullywith this

protected void CalendarDRender(object sender, System.Web.UI.WebControls.DayRenderEventArgs e)
{
string connCalendarString = ConfigurationManager.AppSettings["THConnectionString"];
MySqlConnection cnxCalendar = new MySqlConnection(connCalendarString);
MySqlDataAdapter adapterCalendar = new MySqlDataAdapter();
string cmdCalendarText = "SELECT EventLocation, EventDate FROM eventstable";
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();
// If the month is CurrentMonth
if (!e.Day.IsOtherMonth)
{
foreach (DataRow dr in dsCalendar.Tables[0].Rows)
{
if ((dr["EventDate"].ToString() != DBNull.Value.ToString()))
{
DateTime dtEvent = (DateTime)dr["EventDate"];
if (dtEvent.Equals(e.Day.Date))
{
e.Cell.BackColor = Color.PaleVioletRed;
}
}
}
}
else
{
e.Cell.Text = "";
}
}
This works because the two correct dates are highlighted on the calendar.I think earlier when the gridview was being populated with all dates was because i had a Boundfield tag in there just to see if it was pulling data from the table.sorry if i confused you
0
 
rajeeshmcaCommented:
so is that working according to urr need or what?"
0
 
chrispatonAuthor Commented:
yes that part of it works perfectly.the two dates i have in the table get highlighted on the calendar.it's just the part with the datagrid i'm having problems with
0
 
rajeeshmcaCommented:
if u can wait i will do a sample and send to u later
0
 
chrispatonAuthor Commented:
excellent thank you rajeeshmca
0
 
rajeeshmcaCommented:
HI chrispaton,

The problem is u have not binded the calendarList grid with values as

<asp:TemplateField HeaderText="EventLocation" HeaderStyle-CssClass="gridheading">
                                            <ItemTemplate>
                                                <asp:Label ID="EventLocLabel" runat="server" Text='<%# Eval("EventLocation") %>'>
                                                </asp:Label>
                                            </ItemTemplate>
                                        </asp:TemplateField>
                                        <asp:TemplateField HeaderText="EventDate" HeaderStyle-CssClass="gridheading">
                                            <ItemTemplate>
                                                <asp:Label ID="EventDateLabel" runat="server" Text='<%# Eval("EventDate") %>'>
                                                </asp:Label>
                                            </ItemTemplate>
                                        </asp:TemplateField>

Try with the below aspx page:


<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">
                                            <ItemTemplate>
                                                <asp:Label ID="EventLocLabel" runat="server" Text='<%# Eval("EventLocation") %>'>
                                                </asp:Label>
                                            </ItemTemplate>
                                        </asp:TemplateField>
                                        <asp:TemplateField HeaderText="EventDate" HeaderStyle-CssClass="gridheading">
                                            <ItemTemplate>
                                                <asp:Label ID="EventDateLabel" runat="server" Text='<%# Eval("EventDate") %>'>
                                                </asp:Label>
                                            </ItemTemplate>
                                        </asp:TemplateField>
                                    </Columns>
                                </asp:GridView>
                            </td>
                        </tr>
                    </table>
                </ItemTemplate>
            </asp:FormView>


Code Behind:

protected void Calendar1_SelectionChanged(object sender, EventArgs e)
    {
        Calendar Calendar1 = (Calendar)PropertyForm.FindControl("Calendar1");
        string connCalendarString = @"server=RAJEESH\SQLEXPRESS; database=master; integrated security = true";
       
        SqlConnection cnxCalendar = new SqlConnection(connCalendarString);
        cnxCalendar.Open();
        SqlDataAdapter adapterCalendar = new SqlDataAdapter();
        string cmdCalendarText = string.Format("SELECT EventLocation, EventDate FROM eventtable  
        WHERE EventDate='{0}'", Calendar1.SelectedDate.ToString());
        SqlCommand cmdCalendar = new SqlCommand(cmdCalendarText, cnxCalendar);
        DataSet dsCalendar = new DataSet();
        adapterCalendar.SelectCommand = cmdCalendar;
        adapterCalendar.Fill(dsCalendar);
        GridView CalendarList = (GridView)PropertyForm.FindControl("CalendarList");
        CalendarList.DataSource = dsCalendar;
        CalendarList.DataBind();
    }
0
 
rajeeshmcaCommented:
I thing that will help you...
0
 
chrispatonAuthor Commented:
Hi, thanks for your help.the gridview displays all the dates from my table but doesn't seem to be filtering a selected date from the calendar
0
 
rajeeshmcaCommented:
but that worked for me
0
 
rajeeshmcaCommented:
Did u change your template fireld

<asp:TemplateField HeaderText="EventLocation" HeaderStyle-CssClass="gridheading">
                                            <ItemTemplate>
                                                <asp:Label ID="EventLocLabel" runat="server" Text='<%# Eval("EventLocation") %>'>
                                                </asp:Label>
                                            </ItemTemplate>
                                        </asp:TemplateField>
                                        <asp:TemplateField HeaderText="EventDate" HeaderStyle-CssClass="gridheading">
                                            <ItemTemplate>
                                                <asp:Label ID="EventDateLabel" runat="server" Text='<%# Eval("EventDate") %>'>
                                                </asp:Label>
                                            </ItemTemplate>
                                        </asp:TemplateField>

Try with the below aspx page:
0
 
chrispatonAuthor Commented:
yes changed it exactly as you said but it's pulling all dates from my table and when i click a date on the calendar it does nothing to change it
0
 
rajeeshmcaCommented:
just create a new page and try with my code i have posted earlier (ID: 26086752).
0
 
rajeeshmcaCommented:
Then it should be a problem with CalendarDRender
0
 
chrispatonAuthor Commented:
ok this is all i have now

<%@ Page Language="C#" MasterPageFile="~/austria.master" AutoEventWireup="true" CodeFile="holiday_villa_austria_i_Calendar2.aspx.cs" Inherits="holiday_villa_austria_i" %>
<%@ Register Src="~/Controls/villasearch.ascx" TagName="search" TagPrefix="uc1" %>
<asp:Content ID="Content1" ContentPlaceHolderID="head" Runat="Server">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
</asp:Content>
<asp:Content ID="Content4" ContentPlaceHolderID="MainContent" Runat="Server">
<table width="100%" border="0" cellpadding="2" cellspacing="2" class="maintext">
<tr valign="top">
<td align="left">
<table width="100%" class="PropertyDetailsTable">
<tr>
<td>
<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" 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">
<ItemTemplate>
<asp:Label ID="EventLocLabel" runat="server" Text='<%# Eval("EventLocation") %>'>
</asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="EventDate" HeaderStyle-CssClass="gridheading">
<ItemTemplate>
<asp:Label ID="EventDateLabel" runat="server" Text='<%# Eval("EventDate") %>'>
</asp:Label>
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
</td>
</tr>
</table>
</ItemTemplate>
</asp:FormView>
</td>
</tr>
</table>
</td>
</tr>
</table>
</asp:Content>
and code behind

using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using MySql.Data.MySqlClient;
using System.Text;
using System.Net.Mail;
using System.Drawing;
public partial class holiday_villa_austria_i : System.Web.UI.Page
{
void Page_Load(object sender, EventArgs e)
{ }
protected void Calendar1_SelectionChanged(object sender, EventArgs e)
{
Calendar Calendar1 = (Calendar)PropertyForm.FindControl("Calendar1");
string connCalendarString = ConfigurationManager.AppSettings["THConnectionString"];
MySqlConnection cnxCalendar = new MySqlConnection(connCalendarString);
cnxCalendar.Open();
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();
}
}

Could the problem be with the way the data is stored in the table i have tried it as a date and a datetime
0
 
rajeeshmcaCommented:
Even this is not working... what does this say
0
 
rajeeshmcaCommented:
If this is not workking, the only issue would be with the database date field..
0
 
rajeeshmcaCommented:
In your page_Load you shold fill the FormView
0
 
chrispatonAuthor Commented:
when i click a date now it does the postback and still not filling gridview only have the calendar there and mainheading ' Event Location and Dates'
does it work for you like this?
0
 
rajeeshmcaCommented:
check for whether you have record for that selected date..  for me it works good... if no records then the same thing which u get will be seen here too
0
 
rajeeshmcaCommented:
this is my output
Result.JPG
0
 
chrispatonAuthor Commented:
Thanks rajeeshmca you really stuck with me on this and it works so must be a problem with my table.i will check it and hpefully get it working.much appreciated.good work
0

Featured Post

Hire Technology Freelancers with Gigs

Work with freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely, and get projects done right.

  • 29
  • 27
Tackle projects and never again get stuck behind a technical roadblock.
Join Now