Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

DetailsView - Can not extract values before insert

Posted on 2006-11-08
7
Medium Priority
?
872 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 300 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 300 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
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.

 
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 150 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 300 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 600 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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

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…
IntroductionWhile developing web applications, a single page might contain many regions and each region might contain many number of controls with the capability to perform  postback. Many times you might need to perform some action on an ASP.NET po…
In this video, Percona Solution Engineer Rick Golba discuss how (and why) you implement high availability in a database environment. To discuss how Percona Consulting can help with your design and architecture needs for your database and infrastr…
In response to a need for security and privacy, and to continue fostering an environment members can turn to for support, solutions, and education, Experts Exchange has created anonymous question capabilities. This new feature is available to our Pr…

604 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