?
Solved

How can I prepopulate textbox controls from code behind within the asp.net 3.5 listview control using linq?

Posted on 2009-04-16
4
Medium Priority
?
741 Views
Last Modified: 2013-12-17
Hi,

I have written the attached code to prepopulate textbox controls within the insertitemtemplate of my listview control but the prepopulated data doesn't seem to be dynamic? What I have is two listview controls on seperate pages. When a user clicks a link from the first listview I am passing a variable through the query string to populate the second listview. Now it is here in my second listview that I want to pre-fill the controls in my insertitemtemplate with some of the data from my first listview. The attached code allows me to pre-fill the controls but always with the same data, it's not dynamic data depending on the ID getting passed through the query string? i.e. Say the name "Joe Bloggs" has an ID = 1 and the name "Steven Spielberg" has an ID = 2, when the ID = 2 is getting passed through the query string "Joe Bloggs" is still the name prepopulating my control?
protected void lvAccounts_ItemCreated(object sender, ListViewItemEventArgs e)
    {
        TrustSystemDataContext db = new TrustSystemDataContext();
 
        var query = from ta in db.TrustAccounts
                    join tt in db.Trusts on ta.TrustID equals tt.TrustID
                    join plt in db.PartnerLookups on tt.PartnerCode equals plt.PartnerCode
                    join felt in db.FeeExecLookups on tt.FeeExecCode equals felt.FeeExecCode
                    select new { tt.ClientName, tt.MatterNo, plt.PartnerDescription, felt.FeeExecDescription};
 
        TextBox tbClientInsert = (TextBox)lvAccounts.InsertItem.FindControl("ClientNameInsertTextBox");
        TextBox tbMatterInsert = (TextBox)lvAccounts.InsertItem.FindControl("MatterNoInsertTextBox");
        TextBox tbPartnerInsert = (TextBox)lvAccounts.InsertItem.FindControl("PartnerInsertTextBox");
        TextBox tbFeeExecInsert = (TextBox)lvAccounts.InsertItem.FindControl("FeeExecInsertTextBox");
 
        tbClientInsert.Text = query.First().ClientName;
        tbMatterInsert.Text = query.First().MatterNo;
        tbPartnerInsert.Text = query.First().PartnerDescription;
        tbFeeExecInsert.Text = query.First().FeeExecDescription;
    }

Open in new window

0
Comment
Question by:Shepwedd
  • 2
  • 2
4 Comments
 
LVL 9

Expert Comment

by:Sreedhar Vengala
ID: 24155993
doesn't seem your querying is doing any conditional thing based on ID

something like:
var query = from ta in db.TrustAccounts
join tt in db.Trusts on ta.TrustID equals tt.TrustID
join plt in db.PartnerLookups on tt.PartnerCode equals plt.PartnerCode
join felt in db.FeeExecLookups on tt.FeeExecCode equals felt.FeeExecCode
where tt.ID == 2 // something like this
select new { tt.ClientName, tt.MatterNo, plt.PartnerDescription, felt.FeeExecDescription};

0
 

Author Comment

by:Shepwedd
ID: 24156068
As the ID is being passed through the query string does linq have the equivalent of the SQL: @id? The ID is going to be dynamic so I obviously don't want to hardcode it.

Thanks.
0
 
LVL 9

Accepted Solution

by:
Sreedhar Vengala earned 2000 total points
ID: 24156138
Yes, you need to pass the ID (get passed through your query string) to 'query' to get details based on ID
like: where tt.ID == Convert.ToInt32(Request.QueryString["ID"]);

0
 

Author Closing Comment

by:Shepwedd
ID: 31570894
Great!
0

Featured Post

Restore individual SQL databases with ease

Veeam Explorer for Microsoft SQL Server delivers an easy-to-use, wizard-driven interface for restoring your databases from a backup. No expert SQL background required. Web interface provides a complete view of all available SQL databases to simplify the recovery of lost database

Question has a verified solution.

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

It seems a simple enough task, yet I see repeated questions asking how to do it: how to pass data between two forms. In this article, I will show you the different mechanisms available for you to do just that. This article is directed towards the .N…
A long time ago (May 2011), I have written an article showing you how to create a DLL using Visual Studio 2005 to be hosted in SQL Server 2005. That was valid at that time and it is still valid if you are still using these versions. You can still re…
Despite its rising prevalence in the business world, "the cloud" is still misunderstood. Some companies still believe common misconceptions about lack of security in cloud solutions and many misuses of cloud storage options still occur every day. …
Look below the covers at a subform control , and the form that is inside it. Explore properties and see how easy it is to aggregate, get statistics, and synchronize results for your data. A Microsoft Access subform is used to show relevant calcul…
Suggested Courses

862 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