Solved

How do I extract data from a DetailsView control so I can pass it do a data layer?

Posted on 2008-06-13
6
734 Views
Last Modified: 2008-06-16
I am using a DetailsView control on an ASPX page.  I have designed it so the user can enter 14 different fields, including three dropdown lists.  I cannot bind it directly to a database or even provide it with SQL code that might be passed via ADO or something.

We have a separate data layer where we are to provide all the information we wish to insert into a DB2 table.  It is passed to a COBOL program, which in turn accesses the DB2 database using SQL.

I am totally new to the DetailsView control.  I have become intimate with the GridView control - using it to display data retrieved from the database, allowing the user to update it or delete it, and then passing the appropriate data and commands to the above mentioned data layer.

I assumed I could create the DetailsView interface on the ASPX page, it would captue the data entered into it.  Then I could process its object in code behind... but I am getting nowhere in locating the data in the detailsview object.

Please review the code snippits and comments below and advise.  Thanks in advance!!!!!!
<!-- This is the complete DetailsView (names changed) -->        
 

<asp:DetailsView ID="dtvReceiptsEntry" 

                         runat="server" 

                         Enabled="false"

                         AutoGenerateRows="false"

                         Height="33px" 

                         Width="35%"

                         DefaultMode="Insert"

                         BackColor="#DEBA84" 

                         BorderColor="#DEBA84" 

                         BorderStyle="None" 

                         BorderWidth="1px" 

                         CellPadding="3" 

                         CellSpacing="2" GridLines="Both">
 

            <FooterStyle BackColor="#F7DFB5" ForeColor="#8C4510" />

            <RowStyle BackColor="#FFF7E7" ForeColor="#8C4510" />

            <PagerStyle ForeColor="#8C4510"  />

            <HeaderStyle BackColor="#A55129" Font-Bold="True" ForeColor="White" />

            <EditRowStyle BackColor="#738A9C" Font-Bold="True" ForeColor="White" HorizontalAlign="Left"  />

            <Fields>

                <asp:TemplateField HeaderText="Customer Number">

                    <InsertItemTemplate>

                        <asp:TextBox ID="txtCustomerNumber"   

					                 runat="server" 

					                 Width="80px">

					    </asp:TextBox>

                    </InsertItemTemplate>

                </asp:TemplateField>

                <asp:TemplateField HeaderText="Customer Name">

                    <InsertItemTemplate>

                        <asp:TextBox ID="txtCustomerName" 

                                     runat="server"

                                     width="150px">

                        </asp:TextBox>

                    </InsertItemTemplate>

                </asp:TemplateField>

                <asp:TemplateField HeaderText="Mode Type">

                    <InsertItemTemplate>

                       <asp:DropDownList ID="ddlModeType" 

                                          runat="server" 

                                          DataSourceID="odsuf_rtdata_mfmo"

                                          DataTextField="data_txt" 

                                          DataValueField="key_txt"  

                                          SelectedValue='<%# Eval ("MODE_TY") %>' 

					                      Width="100px" 

                                          CssClass="Bod8">

                        </asp:DropDownList>

                    </InsertItemTemplate>

                </asp:TemplateField>

                <asp:TemplateField HeaderText="Origin City">

                    <InsertItemTemplate>

                        <asp:TextBox ID="txtOrigCity" 

					                 runat="server" 

					                 Width="100px">

					    </asp:TextBox>

                    </InsertItemTemplate>

                </asp:TemplateField>

                <asp:TemplateField HeaderText="Origin State">

                    <InsertItemTemplate>

                        <asp:DropDownList ID="ddlOrigState" 

			                              runat="server" 

			                              Width="100px"  

			                              DatasourceID="odsuf_rtdata_gsta" 

			                              DataTextField="data_txt" 

			                              DataValueField="key_txt" 

			                              SelectedValue='<%# Eval("Orig State") %>'>

			            </asp:DropDownList>
 

                    </InsertItemTemplate>

                </asp:TemplateField>

                <asp:TemplateField HeaderText="Dest City">

                    <InsertItemTemplate>

                        <asp:TextBox ID="txtDestCity"    

					                 runat="server" 

					                 Width="100px">

					    </asp:TextBox>

                    </InsertItemTemplate>

                </asp:TemplateField>

                <asp:TemplateField HeaderText="Dest State">

                    <InsertItemTemplate>

                        <asp:DropDownList ID="ddlDestState" 

					                      runat="server" 

					                      Width="100px"  

					                      DatasourceID="odsuf_rtdata_gsta" 

						                  DataTextField="data_txt" 

						                  DataValueField="key_txt" 

						                  SelectedValue='<%# Eval("Dest State") %>'>

						</asp:DropDownList>
 

                    </InsertItemTemplate>

                </asp:TemplateField>

                <asp:TemplateField HeaderText="Seller's Number">

                    <InsertItemTemplate>

                        <asp:TextBox ID="txtSellerNumber" 

					                 runat="server" 

					                 Width="80px">

					    </asp:TextBox>

                    </InsertItemTemplate>

                </asp:TemplateField>

                <asp:TemplateField HeaderText="Received From">

                    <InsertItemTemplate>

                        <asp:TextBox ID="txtRcvdFrom" 

					                 runat="server" 

					                 Width="100px">

					    </asp:TextBox>

                    </InsertItemTemplate>

                </asp:TemplateField>

                <asp:TemplateField HeaderText="Date Received">

                    <InsertItemTemplate>

                        <asp:TextBox ID="txtDateRcvd" 

					                 runat="server" 

					                 Width="80px">

					    </asp:TextBox>

                    </InsertItemTemplate>

                </asp:TemplateField>

                <asp:TemplateField HeaderText="Manifest Number">

                    <InsertItemTemplate>

                        <asp:TextBox ID="txtManifest" 

					                 runat="server" 

					                 Width="100px">

					    </asp:TextBox>

                    </InsertItemTemplate>

                </asp:TemplateField>

                <asp:TemplateField HeaderText="Net Product">

                    <InsertItemTemplate>

                        <asp:TextBox ID="txtNetProduct" 

					                 runat="server" 

					                 Width="80px">

					    </asp:TextBox>                    

					</InsertItemTemplate>

                </asp:TemplateField>

                <asp:TemplateField HeaderText="Gross Product">

                    <InsertItemTemplate>

                        <asp:TextBox ID="txtGrossProduct" 

					                 runat="server" 

					                 Width="80px">

					    </asp:TextBox>

                    </InsertItemTemplate>                

                </asp:TemplateField>

                <asp:TemplateField HeaderText="Billed Product">

                    <InsertItemTemplate>

                        <asp:TextBox ID="txtBillProduct" 

					                 runat="server" 

					                 Width="80px">

					    </asp:TextBox>

                    </InsertItemTemplate>                

                </asp:TemplateField>

            </Fields>
 

        </asp:DetailsView>
 
 

------------------------- VB 2005 Code Behind -------------------------
 
 

This is where I am really stuck!  I don't know what methodology to access what was entered.  The data entry screen works like a champ.  Just before it is displayed, this code takes place:
 

    Private Sub addColumnHeaders()

        Dim dtbColumnHeaders = New DataTable

        Dim drBlankRows As DataRow

        Dim i As Integer = 0
 

        dtbColumnHeaders.Columns.Add(New DataColumn("Customer Number", GetType(String)))

        dtbColumnHeaders.Columns.Add(New DataColumn("Customer Name", GetType(String)))

        dtbColumnHeaders.Columns.Add(New DataColumn("Mode Type", GetType(String)))

        dtbColumnHeaders.Columns.Add(New DataColumn("Orig City", GetType(String)))

        dtbColumnHeaders.Columns.Add(New DataColumn("Orig State", GetType(String)))

        dtbColumnHeaders.Columns.Add(New DataColumn("Dest City", GetType(String)))

        dtbColumnHeaders.Columns.Add(New DataColumn("Dest State", GetType(String)))

        dtbColumnHeaders.Columns.Add(New DataColumn("Seller's Number", GetType(String)))

        dtbColumnHeaders.Columns.Add(New DataColumn("Received From", GetType(String)))

        dtbColumnHeaders.Columns.Add(New DataColumn("Date Received", GetType(String)))

        dtbColumnHeaders.Columns.Add(New DataColumn("Manifest", GetType(String)))

        dtbColumnHeaders.Columns.Add(New DataColumn("Net Product", GetType(String)))

        dtbColumnHeaders.Columns.Add(New DataColumn("Gross Product", GetType(String)))

        dtbColumnHeaders.Columns.Add(New DataColumn("Billed Product", GetType(String)))
 

     

        drBlankRows = dtbColumnHeaders.NewRow()

        dtbColumnHeaders.Rows.Add(drBlankRows)
 
 

        Session("dtColumnHeaders") = dtbColumnHeaders
 

    End Sub
 
 

Then when the user clicks the Save button after entering the data...
 

  Private Sub btn_save_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btn_save.Click
 

        Try

            dtvReceiptsEntry.DataBind()
 

' I have tried a number of things here.  I will list a couple of 

' examples
 

            Dim txtCustomerNumber As TextBox = CType(dtvReceiptsEntry.Rows(0).FindControl("txtCustomerNumber"), TextBox)

            Dim txtCustomerName As TextBox = CType(dtvReceiptsEntry.Rows(0).FindControl("txtCustomerName"), TextBox)

            Dim ddlModeType As DropDownList = CType(dtvReceiptsEntry.Rows(0).FindControl("ddlModeType"), DropDownList)

            Dim txtOrigCity As TextBox = CType(dtvReceiptsEntry.Rows(0).FindControl("txtOrigCity"), TextBox)

            Dim ddlOrigState As DropDownList = CType(dtvReceiptsEntry.Rows(0).FindControl("ddlOrigState"), DropDownList)

            Dim txtDestCity As TextBox = CType(dtvReceiptsEntry.Rows(0).FindControl("txtDestCity"), TextBox)

            Dim ddlDestState As DropDownList = CType(dtvReceiptsEntry.Rows(0).FindControl("ddlDestState"), DropDownList)

            Dim txtSellerNumber As TextBox = CType(dtvReceiptsEntry.Rows(0).FindControl("txtSellerNumber"), TextBox)

            Dim txtRcvdFrom As TextBox = CType(dtvReceiptsEntry.Rows(0).FindControl("txtRcvdFrom"), TextBox)

            Dim txtDateRcvd As TextBox = CType(dtvReceiptsEntry.Rows(0).FindControl("txtDateRcvd"), TextBox)

            Dim txtManifest As TextBox = CType(dtvReceiptsEntry.Rows(0).FindControl("txtManifest"), TextBox)

            Dim txtNetProduct As TextBox = CType(dtvReceiptsEntry.Rows(0).FindControl("txtNetProduct"), TextBox)

            Dim txtGrossProduct As TextBox = CType(dtvReceiptsEntry.Rows(0).FindControl("txtGrossProduct"), TextBox)

            Dim txtBillProduct As TextBox = CType(dtvReceiptsEntry.Rows(0).FindControl("txtBillProduct"), TextBox)        
 

' The above code does not get errors, but there is no data in those locations either.
 

Without going into code detail, I tried accessing DataKeys collection as well as the DataItem collection.  I futzed with a few others, but I am blundering in the dark at this point.
 

Perhaps the object is not instantiated correctly... the state of the data is out of scope... I am in real need of help.

Open in new window

0
Comment
Question by:NorthReno
  • 3
  • 3
6 Comments
 
LVL 7

Expert Comment

by:skiltz
ID: 21784747
MsgBox(CType(dtvReceiptsEntry.Controls(0).FindControl("txtCustomerName"), TextBox).Text)
0
 

Author Comment

by:NorthReno
ID: 21794573
'MsgBox(CType(dtvReceiptsEntry.Controls(0).FindControl("txtCustomerName"), TextBox).Text)"

No, that does not contain the data... any other ideas?

0
 
LVL 7

Accepted Solution

by:
skiltz earned 500 total points
ID: 21797809
I tried this with your code above and it worked as intended.
0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
LVL 7

Expert Comment

by:skiltz
ID: 21797860
or maybe try 'MsgBox(CType(dtvReceiptsEntry.Items(0).FindControl("txtCustomerName"), TextBox).Text)"
0
 

Author Comment

by:NorthReno
ID: 21798451
Thanks for your input.  I made a discovery earlier.  All I had to do was to change my index from 0 to 1 on the rows collection, and it worked great.  I was using the correct collection all along.
0
 

Author Comment

by:NorthReno
ID: 21798465
skiltz:  I gave you the points anyway.  I really appreciated the time you took to at least make an effort.  No one else offered anything.
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
centralized repository for hosting the internal data and view 1 40
Need a complete list of ASP.NET page load events 3 26
Syntax Error 2 44
SQL Login 17 38
Using Quotation Marks in PHP This question (http://www.experts-exchange.com/Web_Development/Web_Languages-Standards/PHP/Q_28217211.html) seems to come up a lot for developers who are new to PHP.  And it got me thinking, "How can we explain the rule…
Foolproof security solutions has become one of the key necessities of every e-commerce or Internet banking website. If you too own an online shopping site then its vital for you to equip your web portal with customer security features that can allow…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
This video teaches viewers how to create their own website using cPanel and Wordpress. Tutorial walks users through how to set up their own domain name from tools like Domain Registrar, Hosting Account, and Wordpress. More specifically, the order in…

911 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

17 Experts available now in Live!

Get 1:1 Help Now