Find a particular row from grid view using LINQ

This code segment explain you, how to find a particular row from grid view using LINQ

Usually getting a row from a Grid view, we will loop thru the grid view row collection and check for conditions as shown below.

GridViewRow SelectedRow;

foreach (GridViewRow gr in GridView1.Rows)
if ( gr.Cells[1].ToString() == "Value1" && gr.Cells[2].ToString() == "Value2")

SelectedRow = gr;

But we can write same logic as more readable manner in LINQ as shown below.

GridViewRow SelectedRow = GridView1.Rows.OfType().FirstOrDefault(row => row.Cells[1].ToString() == "Value1" && row.Cells[2].ToString() == "Value2");

Link :


Author: Subhashini Janakiraman30 Dec 2010 Member Level: Silver   Points : 1

The type returned by the Linq Query is mostly a collection or anonymous type specified by the keyword var or dim.Hope your assignment is not correct.

  • Do not include your name, "with regards" etc in the comment. Write detailed comment, relevant to the topic.
  • No HTML formatting and links to other web sites are allowed.
  • This is a strictly moderated site. Absolutely no spam allowed.
  • Name: