I am selecting the checked rows from Gridview. To achieve this i have written a lambda expression using dynamic keyword.
var dn = gvLoans.Rows.OfType<dynamic>().Where(s => s.FindControl("chkSelect").Checked == true).Select(s => s.FindControl("lblCD")).ToList();
I want the output of this in List. Can it be achieved by extending the query or i have to write foreach statement.
Blatant rip of the comment posted as an answer.
List<int> lst = gvRankDetails.Rows
.OfType<GridViewRow>()
.Where(s => ((CheckBox)s.FindControl("chkSelect")).Checked)
.Select(s => Convert.ToInt32(((Label)s.FindControl("lblCD")).Text))
.ToList();
OfType is necessary, as GridViewRowCollection implements IEnumerable but not IEnumerable<T>.
public class GridViewRowCollection : ICollection, IEnumerable
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With