Solved

Partially Pre-populate InsertItem with Secondary Datasource

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

A quick way to get a menu to work on our website, is using the Menu control and assign it to a web.sitemap using SiteMapDataSource. Example of web.sitemap file: (CODE) Sample code to add to the page menu: (CODE) Running the application, we wi…
IntroductionWhile developing web applications, a single page might contain many regions and each region might contain many number of controls with the capability to perform  postback. Many times you might need to perform some action on an ASP.NET po…
This is used to tweak the memory usage for your computer, it is used for servers more so than workstations but just be careful editing registry settings as it may cause irreversible results. I hold no responsibility for anything you do to the regist…
Internet Business Fax to Email Made Easy - With  eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, f…

867 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

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now