AJAX Calendar Extender

Capodecina
Permabanned
Joined
31 Dec 2003
Posts
5,172
Location
Barrow-In-Furness
I've added the calendar extended from the control toolkit to my page so I can select the date for a text box.

I've set the textbox to read only so the user has to use the calendar to pick the date, but when I try insert data I get the following error:

SqlDateTime overflow. Must be between 1/1/1753 12:00:00 AM and 12/31/9999 11:59:59 PM.

Really not sure what's going on because the calendar is setting the TextBox to a proper date format like 7/3/08.
 
Nope nothing at all.

The textbox is getting a correct looking value like 3/3/08 like I said. I'm not using any code at all to do this as it's all handled by the calendar extendar control.

Makes it quite hard to try debug anything :(
 
Can you display the date in 4 digit year format or print out the sql statement before it is executed? The only thing that comes into my head is 3/3/0008.
 
Getting a new error now, here's the page code...

"String was not recognized as a valid DateTime. "

Code:
 <asp:DetailsView ID="InsertHoursDetailsView" runat="server" AutoGenerateRows="False"
        DataKeyNames="ID" DataSourceID="ObjectDataSource1" DefaultMode="Insert" GridLines="None"
        Height="50px" Width="450px">
        <Fields>
            <asp:BoundField DataField="ID" HeaderText="ID" InsertVisible="False" ReadOnly="True"
                SortExpression="ID" />
            <asp:TemplateField HeaderText="Date" SortExpression="Date">
                <EditItemTemplate>
                    <asp:TextBox ID="TextBox1" runat="server" Text='<%# Bind("Date") %>'></asp:TextBox>
                </EditItemTemplate>
                <InsertItemTemplate>
                    <asp:TextBox ID="DateTextBox" runat="server" Text='<%# Bind("Date") %>'></asp:TextBox>&nbsp;<asp:Image
                        ID="Image1" runat="server" ImageUrl="~/Images/calendar.png" />
                    &nbsp;
                    <br />
                    <ajaxToolkit:CalendarExtender ID="CalendarExtender1" runat="server" PopupButtonID="Image1"
                        TargetControlID="DateTextBox">
                    </ajaxToolkit:CalendarExtender>
                </InsertItemTemplate>
                <ItemTemplate>
                    <asp:Label ID="Label1" runat="server" Text='<%# Bind("Date") %>'></asp:Label>
                </ItemTemplate>
            </asp:TemplateField>
            <asp:TemplateField HeaderText="Code" SortExpression="TimeCode">
                <EditItemTemplate>
                    <asp:TextBox ID="TextBox2" runat="server" Text='<%# Bind("TimeCode") %>'></asp:TextBox>
                </EditItemTemplate>
                <InsertItemTemplate>
                    <asp:DropDownList ID="TimeCodeDropDownList" runat="server" AppendDataBoundItems="True"
                        DataSourceID="ObjectDataSource1" DataTextField="CodeID" DataValueField="CodeID"
                        Width="156px" SelectedValue='<%# Bind("TimeCode") %>'>
                        <asp:ListItem Value="-1">Please select..</asp:ListItem>
                    </asp:DropDownList><asp:ObjectDataSource ID="ObjectDataSource1" runat="server" DeleteMethod="Delete"
                        InsertMethod="Insert" OldValuesParameterFormatString="original_{0}" SelectMethod="GetCodes"
                        TypeName="ManHoursTableAdapters.tblCodesTableAdapter" UpdateMethod="Update">
                        <DeleteParameters>
                            <asp:Parameter Name="Original_CodeID" Type="Int32" />
                        </DeleteParameters>
                        <UpdateParameters>
                            <asp:Parameter Name="CodeName" Type="String" />
                            <asp:Parameter Name="CodeDescription" Type="String" />
                            <asp:Parameter Name="CodeCategory" Type="String" />
                            <asp:Parameter Name="CodeOwner" Type="String" />
                            <asp:Parameter Name="CodeStatus" Type="String" />
                            <asp:Parameter Name="Original_CodeID" Type="Int32" />
                            <asp:Parameter Name="CodeID" Type="Int32" />
                        </UpdateParameters>
                        <InsertParameters>
                            <asp:Parameter Name="CodeName" Type="String" />
                            <asp:Parameter Name="CodeDescription" Type="String" />
                            <asp:Parameter Name="CodeCategory" Type="String" />
                            <asp:Parameter Name="CodeOwner" Type="String" />
                            <asp:Parameter Name="CodeStatus" Type="String" />
                        </InsertParameters>
                    </asp:ObjectDataSource>
                </InsertItemTemplate>
                <ItemTemplate>
                    <asp:Label ID="Label2" runat="server" Text='<%# Bind("TimeCode") %>'></asp:Label>
                </ItemTemplate>
            </asp:TemplateField>
 
I've worked out what's wrong but I don't know how to fix it?

It doesn't like the date format because it's doing it the American way (Month, Date, Year).

If I input it manually and use 27/03/2008 it works, but if I select the 27th from the Calendar it will use 03/27/2008.
 
Last edited:
When you select a date from the calendar, does it display the correct value in the textbox?
Is it only when inserting into the database, it switches it to mm/dd/yyyy?
 
Have you tried the following?

Go to your textbox in the DetailsView, edit the databindings and select short date from the format property.
 
Yep i've tried that already.

The formatting issue must be with the extender control, why does it have to use the silly American format grr!
 
Back
Top Bottom