We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. Image for the cookie policy date
close icon

Clear row selection

Hi friends,

Sorry for my simple question, but I have searched here and have found no clue on how to deselect (clear selection) on code behind.

Here´s what I´m doing:

ASPX
<asp:UpdatePanel ID="updPanel" runat="server">
<ContentTemplate>
<ej:Grid ID="MyGrid" runat="server" Width="300px" Height="345px" AllowTextWrap="True" Locale="en-US"  DataSourceCachingMode="Session" >
                                  <Columns>
                                      <ej:Column Field="groupID"   HeaderText="Group" TextAlign="Left" HeaderTextAlign="Left" HeaderTooltip="Group ID" />
      <ej:Column Field="groupName" HeaderText="Group" TextAlign="Left" HeaderTextAlign="Left" HeaderTooltip="Group Name"/>
                                 </Columns>
                </ej:Grid>
<asp:LinkButton ID="LinkButton1" OnClick="clearSelection" runat="server" Width="150px">  Clear selection </asp:LinkButton>
</ContentTemplate>
</asp:UpdatePanel>

C-SHARP
public void clearSelection(object sender, EventArgs e)
{
this.MyGrid.SelectedRowIndex = -1;
this.MyGrid.Model.SelectedRowIndex = -1;
this.MyGrid.DataBind();
}

The code above is fired but the selected row is not unselected.
Can you please tell me what I´m missing?

Thank you in advance.


1 Reply

VN Vignesh Natarajan Syncfusion Team April 9, 2019 07:32 AM UTC

Hi Fabio,  
 
Thanks for contacting Syncfusion forums 
 
Query: “I have searched here and have found no clue on how to deselect (clear selection) on code behind. 
 
From your query, we understand that you need to clear the selection from Grid in code behind. We suggest you to clear the SelectedRowindices property in server side along with your code. Refer the below modified code example 
 
// link button click event in server side   
protected void LinkButton1_Click(object sender, EventArgs e) 
        { 
            this.OrdersGrid.SelectedRowIndex = -1; 
            this.OrdersGrid.SelectedRowIndices.Clear(); // clear the selectedRowIndices to clear the selection 
            this.OrdersGrid.DataBind(); 
        } 
 
Please get back to us if you have further queries  
 
Regards, 
Vignesh Natarajan. 


Loader.
Live Chat Icon For mobile
Up arrow icon