Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
935
How to get Checked Rows in Webdatagrid in ClientSide/ServerSide Code
posted

 

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

 

Parents
  • 130
    Suggested Answer
    posted

    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.

     

Reply Children
No Data