• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 745
  • Last Modified:

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

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
Shepwedd
Asked:
Shepwedd
  • 2
  • 2
1 Solution
 
Sreedhar VengalaSr. Consultant - Business IntelligenceCommented:
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
 
ShepweddAuthor Commented:
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
 
Sreedhar VengalaSr. Consultant - Business IntelligenceCommented:
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
 
ShepweddAuthor Commented:
Great!
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now