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
738 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
[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
  • 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
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 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

DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

Question has a verified solution.

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

Since upgrading to Office 2013 or higher installing the Smart Indenter addin will fail. This article will explain how to install it so it will work regardless of the Office version installed.
International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…

730 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