0
votes

I have Tests and Methods Lists.

Tests:

TestName

  • Test1

Methods: MethodName, TestName(look up wit

  • Method1, Test1

  • Method2, Test2

    TestName)

I want to filter methods with caml query by lookup value.

  var metodList = web.Lists["Methods"];

  query.Query = @"<Where><Eq><FieldRef Name='TestName'/>
                  <Value Type='Lookup'>Test1</Value></Eq></Where>";

       var metods = metodList.GetItems(query);

      foreach (SPListItem metodItem in metods.List.Items)
                    {
                        metodViewModelList.Add(new MetodViewModel
                        {
                            MetodId = Convert.ToInt32(metodItem["ID"]),
                            MetodName = metodItem["MethodName"].ToString()
                        });
                    }

But it isn't working. metods.List.items has two items. Method2 is coming too.

Where am i doing wrong?

1

1 Answers

0
votes

Try:

string lkp_metod = metodItem["TestName"].ToString();
SPFieldLookupValue lkp_metod_value = new SPFieldLookupValue(lkp_metod);

MetodId = lkp_metod_value.LookupId.ToString();
MetodName = lkp_metod_value.LookupValue.ToString();