This is a migrated thread and some comments may be shown as answers.

RadGrid deselect not always firing SelectedIndexChanged

4 Answers 390 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Rich
Top achievements
Rank 1
Rich asked on 23 Jul 2010, 03:05 PM
Hello, I have the following RadGrid issue:

Multiple row selection is turned on.
Client side selection is turned on.
ASP.NET AJAX RadGrid version 2009.01.0402.35.

All of this is OK:
When I select a row and then postback, SelectedIndexChanged fires correctly.
When I select a 2nd row and then postback, SelectedIndexChanged fires correctly.
When I select a 3rd row and then postback, SelectedIndexChanged fires correctly.
When I deselect a row and then postback, there are two rows selected, and SelectedIndexChanged fires correctly.
When I deselect another row and then postback, there is one row selected, and SelectedIndexChanged fires correctly.

This is the problem:  When I deselect the final selected row, so there are now no selected rows, and then post back, SelectedIndexChanged does NOT fire.  It happens every time I deselect the final selected row, regardless of how much selecting/deselecting I do.

Here is my ASPX code:
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="AddressTypes.aspx.cs" Inherits="foo.AddressTypes" %>
<%@ Register TagPrefix="telerik" Namespace="Telerik.Web.UI" Assembly="Telerik.Web.UI" %>
 
<html>
    <head runat="server">
        <title>Test Page</title>
    </head>
    <body>
        <form runat="server">
            <asp:ScriptManager ID="sm" runat="server" />
            <asp:ObjectDataSource ID="gridDS" runat="server" TypeName="foo.AddressTypes" SelectMethod="GetRecords" />
            <telerik:RadGrid ID="grid" runat="server" DataSourceID="gridDS" OnSelectedIndexChanged="Grid_SelectedIndexChanged"
                    AllowMultiRowSelection="true">
                <ClientSettings>
                    <Selecting AllowRowSelect="true" />
                </ClientSettings>
            </telerik:RadGrid>
            <asp:Button ID="button" runat="server" Text="Postback" />
        </form>
    </body>
</html>


Here is my code-behind:
using System;
using System.Collections.Generic;
using System.Web.UI;
 
namespace foo
{
    public partial class AddressTypes : Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
        }
 
        public static Dictionary<string, string> GetRecords()
        {
            Dictionary<string, string> dict = new Dictionary<string, string>();
            dict.Add("Test 1", "Test record number 1");
            dict.Add("Test 2", "Test record number 2");
            dict.Add("Test 3", "Test record number 3");
            dict.Add("Test 4", "Test record number 4");
            dict.Add("Test 5", "Test record number 5");
            return dict;
        }
 
        protected void Grid_SelectedIndexChanged(object sender, EventArgs e)
        {
            Response.Write("SELECTED INDEXES: " + grid.SelectedIndexes.Count);
        }
    }
}


Everything works fine until that last selected row is deselected.  All of the row deselection is done using CTRL-Click, and adding a selection column to the grid is not an option.  Can you help me determine why SelectedIndexChanged does not fire when the last selected row is deselected?  Thank you.

Rich

4 Answers, 1 is accepted

Sort by
0
Rich
Top achievements
Rank 1
answered on 26 Jul 2010, 04:38 PM
Quick update: I tried upgrading to the latest version of the RadGrid and the problem still exists.  Thanks!
0
Tsvetina
Telerik team
answered on 28 Jul 2010, 04:00 PM
Hi Rich,

In order to have the SelectedIndexChanged event of RadGrid working properly, I would suggest that you use server-side row selection. You can check this online demo out, as it handles a scenario similar to yours and it is done server-side.

Please, let us know if this helps you achieve the required functionality.

Best wishes,
Tsvetina
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
0
Calvin
Top achievements
Rank 1
answered on 01 Jun 2011, 05:56 PM
I'm having this same issue but I do not want a button or link or anything like the demo, I need the whole row to be selectable and fire events on the server.
0
Tsvetina
Telerik team
answered on 06 Jun 2011, 03:13 PM
Hi Calvin,

You can handle the RowClick client event of the grid and fire a Select command which will cause server-side selection to take place:
OnRowClick

function RowClick(sender, eventArgs) {
    sender.get_masterTableView().fireCommand("Select", eventArgs.get_itemIndexHierarchical());
}


Best wishes,
Tsvetina
the Telerik team

Browse the vast support resources we have to jump start your development with RadControls for ASP.NET AJAX. See how to integrate our AJAX controls seamlessly in SharePoint 2007/2010 visiting our common SharePoint portal.

Tags
Grid
Asked by
Rich
Top achievements
Rank 1
Answers by
Rich
Top achievements
Rank 1
Tsvetina
Telerik team
Calvin
Top achievements
Rank 1
Share this question
or