DetailsView validation fields

Posted on 2006-04-05
Last Modified: 2011-10-03
I create a detailsview to insert data in a table but I don't know how to validate each field that is typed in the page before sending the information to the database.
Question by:Carolinat
    LVL 7

    Expert Comment

    convert the boundfields to template fields and add validators

    instead of
    <asp:BoundField DataField="eventTitle" HeaderText="Title" SortExpression="eventTitle" HtmlEncode="false" />

                                              <asp:TemplateField HeaderText="Title">
                                                          <%# Eval("eventTitle") %>
                                                          <asp:RequiredFieldValidator ControlToValidate="txtEventTitle" ID="RequiredFieldValidator1" runat="server" Text="You must enter a title<br>"></asp:RequiredFieldValidator>
                                                          <asp:TextBox ID="txtEventTitle" MaxLength="50" runat="server" Text='<%# Eval("eventTitle") %>'></asp:TextBox>
    and for the parameters
                      <asp:ControlParameter ControlID="dvEventDetails$txtEventTitle" Name="eventTitle" />

    Author Comment

    Thanks, It worked but the insert link doesn't do anything. What code do I have to add?
    LVL 7

    Expert Comment

    Do you have an insert command and insert parameters on your SqlDataSource?  When you say doesn't do anything, do you mean the page doesn't change, or that no form is displayed?  Is there a JavaScript error?

    Author Comment

    I'm using a Detailsview to create an insert form. Now, I can validate some fields that can't be nulls but when I fill out all of the fields and then click in Insert link it showed me a page with the following error and I don't know why the insert doesn't take the values I'm typing in the form.

    Cannot insert the value NULL into column 'BoxNum', table 'Venus.dbo.Boxes'; column does not allow nulls. INSERT fails.
    The statement has been terminated.
    LVL 7

    Accepted Solution

    post your insert parameters

    the insert parameters will now need to be in the form of

    <asp:ControlParameter ControlID="detailsViewID$textBoxID" Name="eventTitle" />

    for all of them, replace the two IDs with the actual controls IDs, do that for all of them  dvID$controlID

    Author Comment

    I have this

                    <asp:Parameter Name="BoxNum" Type="Int64" />
                    <asp:Parameter Name="Status" Type="String" />
                    <asp:Parameter Name="DateClose" Type="DateTime" />
                    <asp:Parameter Name="DateOpen" Type="DateTime" />
                    <asp:Parameter Name="User" Type="String" DefaultValue="CAROLINA" />
    but still shows me the same error.

    Author Comment

    What should I write in--> Name="eventTitle" ?

    Author Comment

    Thanks, it works perfect.

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    How to run any project with ease

    Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
    - Combine task lists, docs, spreadsheets, and chat in one
    - View and edit from mobile/offline
    - Cut down on emails

    AJAX ModalPopupExtender has a required property "TargetControlID" which may seem to be very confusing to new users. It means the server control that will be extended by the ModalPopup, for instance, if when you click a button, a ModalPopup displays,…
    One of the pain points with developing AJAX, JavaScript, JQuery, and other client-side behaviors is that JavaScript doesn’t allow for cross domain request for pulling content. For example, JavaScript code on could not pull conte…
    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.
    In this tutorial you'll learn about bandwidth monitoring with flows and packet sniffing with our network monitoring solution PRTG Network Monitor ( If you're interested in additional methods for monitoring bandwidt…

    737 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

    18 Experts available now in Live!

    Get 1:1 Help Now