• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1187
  • Last Modified:

DetailsView validation fields

Hi,
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.
0
Carolinat
Asked:
Carolinat
  • 5
  • 3
1 Solution
 
whityumCommented:
convert the boundfields to template fields and add validators

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


use
                                          <asp:TemplateField HeaderText="Title">
                                                <ItemTemplate>
                                                      <%# Eval("eventTitle") %>
                                                </ItemTemplate>
                                                <EditItemTemplate>
                                                      <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>
                                                </EditItemTemplate>
                                          </asp:TemplateField>
and for the parameters
                  <asp:ControlParameter ControlID="dvEventDetails$txtEventTitle" Name="eventTitle" />
0
 
CarolinatAuthor Commented:
Thanks, It worked but the insert link doesn't do anything. What code do I have to add?
0
 
whityumCommented:
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?
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.

 
CarolinatAuthor Commented:
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.
0
 
whityumCommented:
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
0
 
CarolinatAuthor Commented:
I have this

            <InsertParameters>
                <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" />
            </InsertParameters>
but still shows me the same error.
0
 
CarolinatAuthor Commented:
What should I write in--> Name="eventTitle" ?
0
 
CarolinatAuthor Commented:
Thanks, it works perfect.
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.

  • 5
  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now