Solved

Partially Pre-populate InsertItem with Secondary Datasource

Posted on 2007-03-21
2
434 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 500 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

Salesforce Made Easy to Use

On-screen guidance at the moment of need enables you & your employees to focus on the core, you can now boost your adoption rates swiftly and simply with one easy tool.

Question has a verified solution.

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

I recently went through the process of creating a Calendar Control of events with the basis of using a database to keep track of the dates that are selectable, one requirement was to have the selected date pop-up in a simple lightbox.  At first this…
Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
Monitoring a network: why having a policy is the best policy? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the enormous benefits of having a policy-based approach when monitoring medium and large networks. Software utilized in this v…
Do you want to know how to make a graph with Microsoft Access? First, create a query with the data for the chart. Then make a blank form and add a chart control. This video also shows how to change what data is displayed on the graph as well as form…

623 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