How to Clear the Selected Rows selected by checkbox column

Hello,

I have an eJGrid on my web form and I am using Checkbox column to selected the rows. After I have save the changes in button click, I want to Clear the Selection of Row. I used SelectedRowIndices.Clear() method. But one of the selected row was still remain. 

When I trace from code behind, I found that after clearing there SelectedRowIndices.Count become 0. However, when the form was refreshed one of the row was still selected on the UI.
When I trace in click the button event, I saw that SelectedRowIndices.Count become 1 and on of the selection was remain.

Can you please help how to remove the selection.



5 Replies

PK Prasanna Kumar Viswanathan Syncfusion Team September 20, 2018 10:19 AM UTC

Hi Ba Nyar, 
 
Thanks for contacting Syncfusion support. 
 
Based on your requirement you need to clear the selection of a row. But before we proceed with this requirement we need some details, 
 
1. In this you have mentioned that you have save the changes in a button click. So, have you performed any CRUD operations in Grid? If yes, please share the code example. 
 
2. You also mentioned that when the form was refreshed one of the row was still selected. We are unclear about this, please share more details about this. 
 
3. Share the exact requirement in Grid.  
 
4. Share the complete code example of Grid. 
 
To remove the selection in Grid, we suggest you to use clearSelection method of ejGrid. For more information, refer the below document. 
 
 
Regards, 
Prasanna Kumar N.S.V 
 
 



BN Ba Nyar September 24, 2018 02:58 AM UTC

Hi Kumar,

I am preforming the CRUD operation from C# code behind. The ClearSelection method you have mention is from Client side. So I believe I cannot use this method from server side.

Following is my code snippets of CURD operation and Clearing Selection. However, the SelectedIndices was not empty after refresh.



     //This is the code to get the selected Indices and save to DB
     if (grdSearchUser.SelectedRowIndices.Count != 0)
     {
      List<int> selectedIndex = grdSearchUser.SelectedRowIndices;
      List<int> selectedIDs = new List<int>();

      DataOperations ds = new DataOperations();                
      var dataList = ds.Execute(this.CachedSearchUsers, grdSearchUser.Model);

      int pageIndexSize = GetPageIndexSize(true);
      foreach (int i in selectedIndex)
      {
                int rowIndex = i + pageIndexSize;
          UserInfoLightBO_vw obj = (UserInfoLightBO_vw)dataList.Cast<UserInfoLightBO_vw>().ToList()[rowIndex];
                    selectedIDs.Add(obj.UserID);
      }

      isOK = CBLL.AddGroupUsers(this.GroupID, selectedIDs, CU.CurrentUserID);

            }


          //This is the code to clear the Selected Index after saving to DB
          grdGroupUsers.SelectedRowIndices.Clear();
          if (grdGroupUsers.SelectedRowIndices.Count != 0)
          {
              grdGroupUsers.SelectedRowIndices.Remove(0);
    }



PK Prasanna Kumar Viswanathan Syncfusion Team September 24, 2018 11:19 AM UTC

Hi Ba Nyar, 

Thanks for the update. 

Based on your query you need to remove the selection of row when you save the changes in Grid. To clear the selection you have define SelectedRowIndices count as 0, but still one row has been selected.  

We are able to reproduce the reported issue only when we select the records using checkbox and update the record in server-side. The root cause of the issue is when selecting a record we have pushed the row Index to selectedRowIndex property.  

Similarly when multiple rows are selected we have pushed the rowIndex to SelectedRowIndices. In Server-side you have cleared only the selectedRowIndices not the selectedRowIndex property. So, we suggest you to define the SelectedRowIndex property as -1 while clearing the SelectedRowIndices. 

Refer the below code example 

protected void Page_Load(object sender, EventArgs e) 
        { 
            BindDataSource(); 
            Session["InlineEditDataSource"] = order; 
           
            if (OrdersGrid.SelectedRowIndices.Count != 0) 
            { 
                OrdersGrid.SelectedRowIndices.Clear(); 
                OrdersGrid.SelectedRowIndex = -1; 
                OrdersGrid.SelectedRowIndices.Remove(0); 
            } 
        } 

   
If you are still facing the issue, kindly share the following details to reproduce the reported issue at our end. 

  1. Share the full Grid rendering code(code behind also).
  2. Are you using any type of Adaptor?. if yes mention the type.
  3. Share the video demonstration of the issue replication procedure.

Regards, 
Prasanna Kumar N.S.V. 
 



BN Ba Nyar September 25, 2018 01:35 AM UTC

Hi Kumar,

Thanks for your reply. Yes, I am using the Checkbox to multi select. 

The issue is solved after following your step. I noticed that I also need to set Current Page to 1. 

grd.PageSettings.CurrentPage = 1


PK Prasanna Kumar Viswanathan Syncfusion Team September 25, 2018 04:13 AM UTC

Hi Ba Nyar, 

We are happy to hear that your issue has been solved. 

Please get back to us if you need any further assistance. 

Regards, 
Prasanna Kumar N.S.V 


Loader.
Up arrow icon