[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

asp calendar datetime format

Posted on 2009-12-22
8
Medium Priority
?
781 Views
Last Modified: 2012-08-13
i have a calendar that displays the information for a date that has been selected on the calendar in a gridview.when a date starts with a zero ie 2009/12/07 nothing is displayed but works for my other dates like 2009/12/22.what am i missing?
here is my code
<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='<%# DataBinder.Eval(Container.DataItem, "EventDate") %>
'>
                                                </asp:Label>
                                            </ItemTemplate>
                                        </asp:TemplateField>
                                    </Columns>
                                </asp:GridView>

protected void Page_Load(object sender, EventArgs e)
    {
}
    protected void Calendar1_SelectionChanged(object sender, EventArgs e)
    {
 
        Calendar Calendar1 = (Calendar)Form.FindControl("Calendar1");
        string connCalendarString = ConfigurationManager.AppSettings["THConnectionString"];
        MySqlConnection cnxCalendar = new MySqlConnection(connCalendarString);
        cnxCalendar.Open();
        MySqlDataAdapter adapterCalendar = new MySqlDataAdapter();
        string cmdCalendarText = ("SELECT EventLocation, EventDate FROM eventstable WHERE EventDate = ?EventDate");
        MySqlCommand cmdCalendar = new MySqlCommand(cmdCalendarText, cnxCalendar);
        cmdCalendar.Parameters.Add(new MySqlParameter("EventDate", Calendar1.SelectedDate.ToString("yyyy/MM/dd")));
        DataSet dsCalendar = new DataSet();
        adapterCalendar.SelectCommand = cmdCalendar;
        adapterCalendar.Fill(dsCalendar);
        GridView CalendarList = (GridView)Form.FindControl("CalendarList");
        CalendarList.DataSource = dsCalendar;
        CalendarList.DataBind();
    }
}


0
Comment
Question by:chrispaton
  • 5
  • 2
8 Comments
 
LVL 18

Expert Comment

by:Elvio Lujan
ID: 26104557
can you set a break point in the line
cmdCalendar.Parameters.Add(new MySqlParameter("EventDate", Calendar1.SelectedDate.ToString("yyyy/MM/dd")));
and tell us what value you get with "Calendar1.SelectedDate" ??
0
 

Author Comment

by:chrispaton
ID: 26104600
hi,
the value is {07/12/2009 00:00:00}
0
 
LVL 18

Expert Comment

by:Elvio Lujan
ID: 26104644
and why do you use the format "yyyy/MM/dd" intead "MM/dd/yyyy"???
0
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 

Author Comment

by:chrispaton
ID: 26104661
That way seems to be the only way i have found so far that pulls any dates from my table
0
 

Author Comment

by:chrispaton
ID: 26104807
With the date as "MM/dd/yyyy" i get nothing returned.in my table the dates are stored as 2009-12-30
0
 
LVL 2

Expert Comment

by:abelallen
ID: 26104899
Hi chrispaton,

Kindly navigate to the below url and let me know you got the exact solution for the problem...
http://www.obout.com/calendar/tutorial_titletext.aspx

Thanks,
Abel Allen
0
 

Author Comment

by:chrispaton
ID: 26104973
no it's still not pulling dates that start with a zero ie 2009/12/07
0
 

Accepted Solution

by:
chrispaton earned 0 total points
ID: 26105301
ok fixed it there was a problem with my database
0

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

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

Introduction This article shows how to use the open source plupload control to upload multiple images. The images are resized on the client side before uploading and the upload is done in chunks. Background I had to provide a way for user…
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
This lesson discusses how to use a Mainform + Subforms in Microsoft Access to find and enter data for payments on orders. The sample data comes from a custom shop that builds and sells movable storage structures that are delivered to your property. …
Despite its rising prevalence in the business world, "the cloud" is still misunderstood. Some companies still believe common misconceptions about lack of security in cloud solutions and many misuses of cloud storage options still occur every day. …
Suggested Courses
Course of the Month18 days, 6 hours left to enroll

830 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