Zach
Zach

Reputation: 447

Telerik RadGrid not firing OnSelectedIndexChanged when un-selecting last selected item

I have a Telerik RadGrid that is displaying some odd behavior. The grid is defined like so:

<telerik:RadGrid ID="RadGrid1" Width="100%" runat="server"
            AllowSorting="True"
            AllowPaging="true"
            AllowMultiRowSelection="true"
            OnNeedDataSource="RadGrid1_NeedDataSource"
            OnDataBound="RadGrid1_DataBound"
            OnItemDataBound="RadGrid1_ItemDataBound"
            BorderWidth="0"
            OnSortCommand="RadGrid1_SetVisibleTrue"
            OnPageSizeChanged="RadGrid1_SetVisibleTrue"
            OnPageIndexChanged="RadGrid1_SetVisibleTrue"
            OnSelectedIndexChanged="RadGrid1_SelectedIndexChanged"
            AutoGenerateColumns="False">
            <ClientSettings EnablePostBackOnRowClick="true">
                <Selecting AllowRowSelect="true" />                                        
            </ClientSettings>
            <MasterTableView DataKeyNames="LabID, MachineName, PointID, MachCond, LubCond, Lubricant, CustReview, CustReviewDte, MachineID" ClientDataKeyNames="MachineName" AllowMultiColumnSorting="true">
                <SortExpressions>
                    <telerik:GridSortExpression FieldName="MachineName" SortOrder="Ascending" />
                    <telerik:GridSortExpression FieldName="MachineNumber" SortOrder="Ascending" />
                </SortExpressions>
                <Columns>.........</Columns>
            </MasterTableView>
</telerik:RadGrid>

My OnSelectedIndexChanged event is defined in the code behind:

protected void RadGrid1_SelectedIndexChanged(object sender, EventArgs e)
    {
       //Do stuff
    }

When I have more than one visible item selected, the event is fired every time I select or un-select a row, as I expect. However, if there is only one visible selected item in the grid, and I un-select it, the event is not fired! Why is this?

Thanks for your help!

Upvotes: 1

Views: 3842

Answers (1)

Rahul Nikate
Rahul Nikate

Reputation: 6337

What you describe is expected behavior for the RadGrid. When an item is selected or deselected from the client the SelectedItems collection is updated. This collection is checked on the server prior firing the OnSelectedIndexChanged event. If SelectedItems collection has no elements the event is not fired.

Since you have set the EnablePostBackOnRowClick property to true, postback is performed after every click on a row. In this case you could use the PreRender method to check the number of elements in the SelectedItems collection. When the number reaches zero you could execute the logic you would like to implement.

Upvotes: 1

Related Questions