?
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
Medium Priority
?
742 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 1500 total points
ID: 21797809
I tried this with your code above and it worked as intended.
0
Get MySQL database support online, now!

At Percona’s web store you can order your MySQL database support needs in minutes. No hassles, no fuss, just pick and click. Pay online with a credit 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

Get 15 Days FREE Full-Featured Trial

Benefit from a mission critical IT monitoring with Monitis Premium or get it FREE for your entry level monitoring needs.
-Over 200,000 users
-More than 300,000 websites monitored
-Used in 197 countries
-Recommended by 98% of users

Question has a verified solution.

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

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.
Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
This video teaches users how to migrate an existing Wordpress website to a new domain.
Wufoo.com provides powerful tools for surveying targeted groups, and utilizing data from completed surveys to find trends, discover areas of demand or customer expectation, and make business decisions on products or services.
Suggested Courses

777 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