Click here to Skip to main content
15,891,910 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hii ,

I have two list items ..
say list1 conatins id , default text , Nmae

lis2 contains id, UpdatedText,Name

Now i want to update list one from updated value of list 2 whose id matches to each other ..

please suggest //

i tried something like this ..

C#
if (lstPerformanceObjectives.Count > 0)
{
   foreach (Label update in lstPerformanceObjectives)
   {
      List<actuslibrary.midyearcustomtext> lstMid = ActusLibrary.MidYearCustomText.GetMidYearCustomTextBuCompanyId(ApConfig.CurrentCompany.CompId);
      if (lstMid != null)
      {
         if (update.ID == "lblCommentsonJobDescription")
         {
            string text = lstMid.FirstOrDefault(p => p.DefaultText == "Comments on Job Description").DefaultText.ToString();

            // update.Text = lstMid.FirstOrDefault(p => p.DefaultText == "Comments on Job Description").UpdatedText.ToString() == null ?
            // lstMid.FirstOrDefault(p => p.DefaultText == "Comments on Job Description").DefaultText.ToString() :
            // lstMid.FirstOrDefault(p => p.DefaultText == "Comments on Job Description").UpdatedText.ToString()
            // ;
         }
      }
   }
}


[edit]Code block added, HTML encoded - OriginalGriff[/edit]
[edit]Tabulation reduced to improve readability[/edit]
Posted
Updated 27-Feb-14 23:34pm
v4
Comments
OriginalGriff 28-Feb-14 4:05am    
This is not a good question - we cannot work out from that little what you are trying to do.
Remember that we can't see your screen, access your HDD, or read your mind.
So where are you lists? Are we talking databases, or XML files, or Generic List in C#? How do you need them updated?
Use the "Improve question" widget to edit your question and provide better information.
Torakami 28-Feb-14 4:10am    
check my update question
Torakami 28-Feb-14 4:14am    
I am not able to find perticular text using lamda expression
OriginalGriff 28-Feb-14 4:24am    
Well, that's going to depend on a couple of things - notably your midyearcustomtext.DefaultText property, which we can't see.
There is also the fun that FirstOrDefault returns null as a default for reference types if there are none matching the criteria, so your lambda must be working to an extent or you will get an exception.

What happens if you run this in the debugger?

try with this.
list1Obj =Unit object from list 1
C#
List1.Where(list1Obj => list1Obj.Id == list2[0].Id)
      .Select(list1Obj =>
    {
      list1Obj.defaulttext= Convert.ToString(list2[0].UpdatedText);
      return AccGroupObj;
    })
    .ToList();
 
Share this answer
 
v3
Comments
Torakami 28-Feb-14 4:45am    
just tell me only one thing why my lamda expression for list is not working .

string text = lstMid.FirstOrDefault(p => p.DefaultText == "Comments on Job Description").DefaultText.ToString();

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900