Solved

Partially Pre-populate InsertItem with Secondary Datasource

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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

ASP.Net to Oracle Connectivity Recently I had to develop an ASP.NET application connecting to an Oracle database.As I am doing it first time ,I had to solve several problems. This article will help to such developers  to develop an ASP.NET client…
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an antispam), the admini…
Attackers love to prey on accounts that have privileges. Reducing privileged accounts and protecting privileged accounts therefore is paramount. Users, groups, and service accounts need to be protected to help protect the entire Active Directory …

740 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