Solved

Partially Pre-populate InsertItem with Secondary Datasource

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

Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

Join & Write a Comment

Just a quick little trick I learned recently.  Now that I'm using jQuery with abandon in my asp.net applications, I have grown tired of the following syntax:      (CODE) I suppose it just offends my sense of decency to put inline VBScript on a…
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.
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…
You have products, that come in variants and want to set different prices for them? Watch this micro tutorial that describes how to configure prices for Magento super attributes. Assigning simple products to configurable: We assigned simple products…

705 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

19 Experts available now in Live!

Get 1:1 Help Now