Link to home
Start Free TrialLog in
Avatar of Simon Cripps
Simon CrippsFlag for United Kingdom of Great Britain and Northern Ireland

asked on

Using Calendar in Detailsview for insert and update

Hi, I am trying to use a calendar in the detailsview to edit and update a field. However I am running into a couple of problems.
1) The control does not update the records when in update mode. Cade is attached below, I can't see why it does not update.
2) In insert mode as the calendar expects a value I have tried to set the default values in the SQL table to 01/01/2010 - in table definition the  "Defalt Value or Binding" is set to (((1)/(1))/(2010)) - However I am getting the error SqlDateTime overflow. Must be between 1/1/1753 12:00:00 AM and 12/31/9999 11:59:59 PM, somehow my defaul value is not being used as I insert,

Can you help resolve these issues on insert/edit calendar date in Detailsview.
<asp:TemplateField HeaderText="VCStartDate" SortExpression="VCStartDate">
                <EditItemTemplate>
           <%--         <asp:TextBox ID="TextBox1" runat="server" Text='<%# Bind("VCStartDate") %>'></asp:TextBox>
          --%>         <asp:Calendar ID="Calendar1" runat="server" SelectedDate='<%# Bind("VCStartDate") %>' VisibleDate='<%# Bind("VCStartDate") %>'></asp:Calendar>
                
                </EditItemTemplate>
                <InsertItemTemplate>
<%--                    <asp:TextBox ID="TextBox1" runat="server" Text='<%# Bind("VCStartDate") %>'></asp:TextBox>
--%>                   <asp:Calendar ID="Calendar1" runat="server" SelectedDate='<%# Bind("VCStartDate") %>'  VisibleDate='<%# Bind("VCStartDate") %>'></asp:Calendar>
  
                </InsertItemTemplate>
                <ItemTemplate>
                    <asp:Label ID="Label2" runat="server" Text='<%# Bind("VCStartDate") %>'></asp:Label>
                </ItemTemplate>

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of Alan Warren
Alan Warren
Flag of Philippines image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Simon Cripps

ASKER

Thanks, I am trying to apply this, however I am not getting as far to test this out. From what I gather I need to use the calendat to populate the textboxes with the date and then validated against the textboxes. But I cant get the textboxes in the details view to be populated with either a default value when it is a new insertion or a selected value from the calendar.

I have tired to use OnSelectionChanged in the calendar control, however in the code it erros that textBox1 and Calendar1 are not declared. They are both set to runat=server, however it seams that as they are in the detailsview control they cannot be seen.

<asp:Calendar ID="Calendar1" runat="server" OnSelectionChanged="Calendar1_SelectionChanged"  SelectedDate='<%# Bind("VCStartDate") %>'  VisibleDate='<%# Bind("VCStartDate") %>'></asp:Calendar>

Protected Sub Calendar1_SelectionChanged(ByVal sender As Object, ByVal e As System.EventArgs)
TextBox1.value = Calendar1.value

How do I get a defaul value abd Selected calendar value to populate the Textbox?
Many thanks in advance for your assistance.