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

x
?
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
?
743 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
Understanding Web Applications

Without even knowing it, most of us are using web applications on a daily basis. Gmail and Yahoo email, Twitter, Facebook, and eBay are used by most of us daily—and they are web applications. We often confuse these web applications tools for websites.  So, what is the difference?

 
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

Plesk WordPress Toolkit

Plesk's WordPress Toolkit allows server administrators, resellers and customers to manage their WordPress instances, enabling a variety of development workflows for WordPress admins of all skill levels, from beginners to pros.

See why 2/3 of Plesk servers use it.

Question has a verified solution.

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

You can of course define an array to hold data that is of a particular type like an array of Strings to hold customer names or an array of Doubles to hold customer sales, but what do you do if you want to coordinate that data? This article describes…
While opting for any web-to-print solution, you need to discuss with your team and some of your end users and know their opinions about your decisions. In this article we list down some questions you need to ask yourself.
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
Suggested Courses

610 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