Solved detailsview change data before update

Posted on 2008-11-07
Last Modified: 2012-05-05
I have a detailview showing data from an MS SQL 2000 table.  It shows fldtaskname, fldstartdate, and fldclosedate.  In edit mode I have put a dropdown list with the values Yes and No.  If the user selects Yes I want to put todays date in the fldCloseDate, if they select No I want to leave the field unchanged.

How do I intercept the update and convert Yes to todays date, or convert No to null value?

<asp:TemplateField HeaderText="Close" SortExpression="fldCloseDate">
<asp:DropDownList ID="DropDownList2" runat="server">
<asp:ListItem Selected="True">No</asp:ListItem>
<asp:Label ID="Label4" runat="server" Text='<%# Bind("fldCloseDate", "{0:dd/MM/yyyy}") %>'></asp:Label>
Question by:iepaul
    1 Comment
    LVL 83

    Accepted Solution

    Create a SelectedIndexChanged event for the dropdownlist2. Set the autopostback property to true. Inside the event, check whether the text in the list is yes or no and set the date accordingly. For example

    if dropdownlist2.text="Yes" then
    end if

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    How your wiki can always stay up-to-date

    Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
    - Increase transparency
    - Onboard new hires faster
    - Access from mobile/offline

    This tutorial demonstrates one way to create an application that runs without any Forms but still has a GUI presence via an Icon in the System Tray. The magic lies in Inheriting from the ApplicationContext Class and passing that to Application.Ru…
    Introduction When many people think of the WebBrowser ( control, they immediately think of a control which allows the viewing and navigation of web pages. While this is true, it's a…
    It is a freely distributed piece of software for such tasks as photo retouching, image composition and image authoring. It works on many operating systems, in many languages.
    This video is in connection to the article "The case of a missing mobile phone (". It will help one to understand clearly the steps to track a lost android phone.

    759 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

    Need Help in Real-Time?

    Connect with top rated Experts

    11 Experts available now in Live!

    Get 1:1 Help Now