I added UnboundCheckBoxField on my webdatagrid.
<ig:UnboundCheckBoxField HeaderChecked="False" Key="CheckBox" Width="50">
<Header Text="" />
</ig:UnboundCheckBoxField>
Now i want to get all rows that i checked in my grid.
I tried this:
BLOCKED SCRIPT
var countcheckedrows = $find("<%=fgWebDataGrid.ClientID%>").get_behaviors().get_selection().get_selectedRows().get_length();
codebehind:
var countchecked = fgWebDataGrid.Behaviors.Selection.SelectedRows.Count;
but it just returns only 1or 0.
Thanks in Regards
I notice in this thread that some are proposing solutions that work client side while others are proposing server side solutions. I don't want my page posting back to the server every time a user checks a checkbox so that solution is undesirable to me. And, I want a server side solution. This seems to work the best for me:
WebDataGrid1.Behaviors.Paging.Enabled = false;
int[] ids = WebDataGrid1.Rows .Cast<GridRecord>() .Where(gr => (bool)((Infragistics.Web.UI.GridControls.UnboundCheckBoxGridRecordItem)gr.Items[0]).Value) .Select(gr => (int)(gr.Items[1].Value)).ToArray();
WebDataGrid1.Behaviors.Paging.Enabled = true;
That code assumes that the checkbox is in the first column (index 0) and that a primary key is in the second column (index 1) and of type int. The call returns an array of the checked ids. If you are using paging, you must turn off paging before the call and turn it back on afterwards.
Just a bit more info.
if you are using paging in your grid and don't turn it off (like I do in the example above), you will only get the checked rows on the currently selected page because the grid's Rows collection will only contain the current page's records.
If your column containing the primary key is other than column 1, just change the Items index to the appropriate value in the Select clause.
If your primary key is not an int, change the casting in the Select clause to the correct type and change the ids variable data type to the correct type.