Hey guys,
I have a few Lists of strings containing elements saved from a Gridview on the page.
(2 different gridviews with datasource from same database and table but showing different information)

I need to write a logic which is ~10 if statements checking some conditions and then write a KML string (setting a different picture of a placemark in Google Earth).

The code looks like that:

for (int i = 0; i < latList.Count; i++) // going through the list of latitudes and see how many are they - then create placemark for each one taking the latitude and longitude (from Gridview on the page)
                              {
                                  kml.WriteStartElement("Placemark");
                                  kml.WriteElementString("name", "Pad " + GridView1.Rows[i].Cells[0].Text);
                                  

                                  for (int j = 0; j < datesList.Count; j++) // another for loop going through list of dates and for every empty element in the list and where the list of tasks contains "someString", write KML element with the appropriate picutre
                                  {
                                      string date = datesList[i];
                                      string tasks = GridView2.Rows[i].Cells[0].Text;

                                      if ((!String.IsNullOrWhiteSpace(date) && date != "&nbsp;") && tasksList.Where(task => task.Contains("Pre-Commissioning")))
                                      {
                                          kml.WriteElementString("styleUrl", "#randomColorIcon2");
                                      }
                                      else
                                      {
                                          kml.WriteElementString("styleUrl", "#randomColorIcon");
                                      }

                                     
                                  }

So what I need in the if statement here is to use both conditions. But it seems that I cannot use the Where method of a list. Not even as one condition in the if...
I tried using list.Contains("") but still not getting the correct result.
The if statement has to check if both conditions are true and ONLY IF they are - write the first line of kml.WriteElementString... else set the normal picture of the placemark.

I hope it is understandable and you can point me in the right direction.
Sorry if something is unclear, please ask and I will try to explain it better.

Recommended Answers

All 6 Replies

Are you asking the program if Any of the elements of the list is "Pre-Commissioning"?
...or something else?

Yeah.. what it has to do is:

for every element in the list which is not empty, AND another list containing "Pre-Commissioning"
->then put pic1 for the placemark

When I think about it now... I don't now how these two lists will be related to each other :?? maybe this is what I'm doing wrong. I mean, the two lists are filled with the elements from 2 columns in a gridview but then how it's going to now that on row 3 for example we have both "pre-commissioning" and "not empty date"...

Can you follow me? Or it's still pretty confusing

Thanks

You put that inside of an "if" statement, so it's is not doing what you're thinking.
If you're attempting to search the contents of two lists, you'll need to use Union instead of "&&"

Can you be more specific ... Union is used in sql isn't it ?

Union is also used in Linq. You invoked Linq with that .Where clause.

hey pepyrs ,
Is your code working now.
Actual im also stuck in same issue.

Can you please tell me where this code needs to be written , is this include in kml file only ??

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.