Solved

DetailsView - Can not extract values before insert

Posted on 2006-11-08
7
867 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
[X]
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
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
Salesforce Has Never Been Easier

Improve and reinforce salesforce training & adoption using WalkMe's digital adoption platform. Start saving on costly employee training by creating fast intuitive Walk-Thrus for Salesforce. Claim your Free Account Now

 
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: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying 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

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 www.johnchapman.name could not pull conte…
I recently went through the process of creating a Calendar Control of events with the basis of using a database to keep track of the dates that are selectable, one requirement was to have the selected date pop-up in a simple lightbox.  At first this…
In this video, viewers are given an introduction to using the Windows 10 Snipping Tool, how to quickly locate it when it's needed and also how make it always available with a single click of a mouse button, by pinning it to the Desktop Task Bar. Int…
Monitoring a network: how to monitor network services and why? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the philosophy behind service monitoring and why a handshake validation is critical in network monitoring. Software utilized …

688 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