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
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.
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.
Hi NewbApps,
Please do not hesitate to contact me if you need further assistance.
Apologies for the delayed response.
Is the issue occurring with build 2055? So far I am unable to replicate this behavior. A sample illustrating the matter would be greatly appreciated. Any additional information you can provide me with would help to isolate the matter.
Please feel free to contact me if you have any additional questions.
Hi Petar,
I got new problem.
paging is not ok with clearing unbound checkbox during initialize row.
e.Row.Items[0].Value = false;
this is the error:
.Async request failed
[InvalidOperationException]: Error during serialization or deserialization using the JSON JavaScriptSerializer. The length of the string exceeds the value set on the maxJsonLength property.
etch..