?
Solved

DetailsView - Can not extract values before insert

Posted on 2006-11-08
7
Medium Priority
?
869 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
Industry Leaders: 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!

 
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

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

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

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…
The article shows the basic steps of integrating an HTML theme template into an ASP.NET MVC project
Do you want to know how to make a graph with Microsoft Access? First, create a query with the data for the chart. Then make a blank form and add a chart control. This video also shows how to change what data is displayed on the graph as well as form…
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…

764 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