kamagra how much to take

Getting Selected ListItem’s Using LINQ

I had a friend just show me this really simple way when you are employing a ListBox control and want to get the ListItem.Selected items using LINQ in strongly typed collection to execute FirstOrDefault() etc.

Simply use:

As a lambda expression:

  1. var box = new ListBox();
  2. var selectedItems = box.Items.Cast<ListItem>().Where(li => Equals(li.Selected, true));

As a statement:

  1. var box = new ListBox();
  2. var selectedItems = box.Items.Cast<ListItem>().Where(li => { return Equals(li.Selected, true); });

Really simple!

Share

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>