Solved

DetailsView - Can not extract values before insert

Posted on 2006-11-08
7
852 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
What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

 
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

What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

Just a quick little trick I learned recently.  Now that I'm using jQuery with abandon in my asp.net applications, I have grown tired of the following syntax:      (CODE) I suppose it just offends my sense of decency to put inline VBScript on a…
ASP.Net to Oracle Connectivity Recently I had to develop an ASP.NET application connecting to an Oracle database.As I am doing it first time ,I had to solve several problems. This article will help to such developers  to develop an ASP.NET client…
Internet Business Fax to Email Made Easy - With eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…
Illustrator's Shape Builder tool will let you combine shapes visually and interactively. This video shows the Mac version, but the tool works the same way in Windows. To follow along with this video, you can draw your own shapes or download the file…

706 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

16 Experts available now in Live!

Get 1:1 Help Now