Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people, just like you, are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
Solved

DetailsView - Can not extract values before insert

Posted on 2006-11-08
7
858 Views
Last Modified: 2007-12-19
How do you extract the values from the textboxes in a DetailsView before the insert. I want to validate the values and make sure a date is a data, a number is a number, etc. Otherwise, I get a runtime error. I need VB code please.
0
Comment
Question by:wrwiii12
7 Comments
 
LVL 96

Assisted Solution

by:Bob Learned
Bob Learned earned 100 total points
ID: 17905570
Do you have any validators?

Bob
0
 
LVL 4

Author Comment

by:wrwiii12
ID: 17905906
Here is what VS2005 created automatically when i created a DetailsView.

    <asp:DetailsView ID="DetailsView1" runat="server" AutoGenerateRows="False" CellPadding="4"
        DataKeyNames="Cable_Number" DataSourceID="SqlDataSource1" DefaultMode="Insert"
        ForeColor="#333333" GridLines="None" Height="50px" Width="402px">
        <FooterStyle BackColor="#5D7B9D" Font-Bold="True" ForeColor="White" />
        <CommandRowStyle BackColor="#E2DED6" Font-Bold="True" />
        <EditRowStyle BackColor="#999999" />
        <RowStyle BackColor="#F7F6F3" ForeColor="#333333" />
        <PagerStyle BackColor="#284775" ForeColor="White" HorizontalAlign="Center" />
        <Fields>
            <asp:BoundField DataField="Cable_Number" HeaderText="Cable_Number" ReadOnly="True"
                SortExpression="Cable_Number" />
            <asp:BoundField DataField="LocationA" HeaderText="LocationA" SortExpression="LocationA" />
            <asp:BoundField DataField="LocationB" HeaderText="LocationB" SortExpression="LocationB" />
            <asp:BoundField DataField="Special_Instructions" HeaderText="Special_Instructions"
                SortExpression="Special_Instructions" />
            <asp:BoundField DataField="Length" HeaderText="Length" SortExpression="Length" />
            <asp:CommandField ShowInsertButton="True" />
        </Fields>
        <FieldHeaderStyle BackColor="#E9ECF1" Font-Bold="True" />
        <HeaderStyle BackColor="#5D7B9D" Font-Bold="True" ForeColor="White" />
        <AlternatingRowStyle BackColor="White" ForeColor="#284775" />
    </asp:DetailsView>

I did some research on the validators you were referring to. How do i refer to a specific textbox(ie Cable_Number). I need for that to be a required field coupled with the LocationA & LocationB. The Special_instructions and Length are not required. Thanks!
0
 
LVL 96

Assisted Solution

by:Bob Learned
Bob Learned earned 100 total points
ID: 17905922
If you want to validate a row, then you would need a template field instead of a bound field, then you could use a RequiredFieldValidator with ControlToValidate set to the ID for the TextBox used in the template field.

Bob
0
Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

 
LVL 4

Author Comment

by:wrwiii12
ID: 17906952
I guess I just don't understand because I'm running in uncharted territory. Anything outside of vb code and what VS2005 creates automatically, I'm lost. I want the Cable_Number textbox to be manditory and when they enter a value, i want it to be inserted into the sql db. How can you create an unbound textbox and yet be tied to the sql datasource and also allow me to do validation on the text they enter.
0
 
LVL 4

Assisted Solution

by:glebn
glebn earned 50 total points
ID: 17920033
Validation is done in ASP.NET by setting the causes validation property to true and then writing validation rules. Once you see how it works I think you'll find it much better than having to write validation code for every control!

Time to do a little reading on validation in ASP.NET. I too like to jump in and start producing something, but sometimes stepping back for a few hours and reading will save a lot of time and hair pulling!

Here are some links:

General Quickstart
http://quickstarts.asp.net/QuickStartv20/aspnet/

Validation
http://quickstarts.asp.net/QuickStartv20/aspnet/doc/validation/default.aspx

I also highly recommend several Wrox ASP books,
ASP.NET 2.0 Instant Results - a several of sample applications explained in detail
Professional ASP.NET 2.0 - great discussion of all core ASP.NET areas
0
 
LVL 96

Assisted Solution

by:Bob Learned
Bob Learned earned 100 total points
ID: 17922438
Here is another possibility:

ASP.NET Required TextBox (Graphical RequiredFieldValidator)
http://www.codeproject.com/aspnet/RequiredTextBox.asp

<Quote>
I will show you all how I went about creating my RequiredTextBox, comprising a System.Web.UI.WebControls.TextBox and a customized RequiredFieldValidator. The finished product is a drag and drop text box that is set as a required field, and has an error provider look and feel similar to the System.Windows.Forms.ErrorProvider.
</Quote>

Bob
0
 

Accepted Solution

by:
cpaino earned 200 total points
ID: 18072453
add <asp:DetailsView  OnItemInserting = "StoresDetailView_ItemInserting" blablalb


then add to the .vb

    Sub StoresDetailView_ItemInserting(ByVal sender As Object, ByVal e As DetailsViewInsertEventArgs)

        ' Get the state value from the DropDownList control in the
        ' DetailsView control.
        'Dim tempdrpDwn As DropDownList =
        If CType(DetailsView1.Rows(2).FindControl("checkbox1"), CheckBox).Checked() Then
            e.Values("send") = "1" '' found in the insertitemtemplate
        Else
            e.Values("send") = "0"  ' found in the insertitemtemplate
        End If

    End Sub

change the content of the code to suit your needs
0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
ASP.NET MVC 2 40
tutorial for ebay api 3 55
Object Oriented Programming, C#, referencing, scoping. 13 69
Google Maps with Webforms 1 12
User art_snob (http://www.experts-exchange.com/M_6114203.html) encountered strange behavior of Android Web browser on his Mobile Web site. It took a while to find the true cause. It happens so, that the Android Web browser (at least up to OS ver. 2.…
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
This video shows how to quickly and easily add an email signature for all users on Exchange 2016. The resulting signature is applied on a server level by Exchange Online. The email signature template has been downloaded from: www.mail-signatures…
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…

840 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