Link to home
Start Free TrialLog in
Avatar of Ryan Chong
Ryan ChongFlag for Singapore

asked on

How to use LINQ to get selected items (checkboxes) within a GridView control that allow paging?

I'm exploring the possibility to use LINQ to get selected items (checkboxes) within a GridView control that allow paging.


Checkbox is added like this:

<asp:TemplateField>
                      <ItemTemplate>
                      <asp:CheckBox ID="chk" runat="server" />
                      </ItemTemplate>
                      </asp:TemplateField>


Anyone can advise here? Thanks
ASKER CERTIFIED SOLUTION
Avatar of abel
abel
Flag of Netherlands image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
(PS: there's also a LINQ zone, in case you want to make any follow-up questions....;-).
Avatar of Ryan Chong

ASKER

Hi there,

Thanks for your codes, have some fun with it, and my final outcome is something like below:

var checkedIDs = from GridViewRow row in GridView1.Rows
                            where (row.FindControl("chk") as CheckBox).Checked
                            select (row.FindControl("id") as HiddenField).Value;


//....

cheers
Looks good. Tx for the grade! ;-)