Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Partially Pre-populate InsertItem with Secondary Datasource

Posted on 2007-03-21
2
Medium Priority
?
437 Views
Last Modified: 2010-07-27
I have one field in a Formview's InsertItemTemplate that I would like to pre-populate from a datasource other than the one that is bound to the FormView.

The details are as such: my main page allows a user to create a new relational record for a customer.  When a button is clicked to create this new record a formview is presented in a new window.  The URL contains two query parameters, editorWorkorder.aspx?id=new&companyId=232 .  The id=new puts the formview into Insert mode, and the companyId=232 determines should be saved along the new workorder so I'll know what company the new workorder belongs to.

Everything works fine.  However, I realized I would like to display the company's name in the formview while it is in Insert mode to remind the user what company the workorder is being created for.  Also because I just really, really want to.

I can retrieve the company's name through another query, but how would I get the name to display in a label inside the formview while the formview is in insert mode and bound to a differnt datasource than I am retireving the company name from?
0
Comment
Question by:manicsquirrel
[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
2 Comments
 
LVL 20

Accepted Solution

by:
brwwiggins earned 2000 total points
ID: 18765526
I would create a function that takes the companyID as a parameter and returns the company name. Then you can put a label in the InserItemTemplate and set the text = '<%# FunctionName(Eval("companyID")) %>'

Then in your function do a lookup on the database and return the compnay name for that specific ID
0
 
LVL 6

Author Comment

by:manicsquirrel
ID: 18766029
That's exactly what I did.  Shame on me thinking there was an easier way - not that this was hard.  Thanks for your reply.

************code-behind ************************
Protected Function getCompanyName() As String
        Dim str As String = ConfigurationManager.ConnectionStrings("dmsdata").ConnectionString
        Using con As New SqlConnection(str)
            Dim cmd As New SqlCommand("SELECT Company FROM dmsCompany WHERE ID='" & _companyID & "'", con)
            con.Open()
            Dim rdr As SqlDataReader = cmd.ExecuteReader()
            Try
                While rdr.Read()
                    Return rdr.GetString(0)
                End While
            Finally
                rdr.Close()
            End Try
        End Using
        Return ""
    End Function

****************aspx **************************
<asp:Label ID="Company" runat="server" Text="<%# getCompanyName() %>" </asp:Label>
0

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Introduction This article shows how to use the open source plupload control to upload multiple images. The images are resized on the client side before uploading and the upload is done in chunks. Background I had to provide a way for user…
The ECB site provides FX rates for major currencies since its inception in 1999 in the form of an XML feed. The files have the following format (reducted for brevity) (CODE) There are three files available HERE (http://www.ecb.europa.eu/stats/exch…
Monitoring a network: how to monitor network services and why? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the philosophy behind service monitoring and why a handshake validation is critical in network monitoring. Software utilized …
Want to learn how to record your desktop screen without having to use an outside camera. Click on this video and learn how to use the cool google extension called "Screencastify"! Step 1: Open a new google tab Step 2: Go to the left hand upper corn…

688 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