Grid Sort Event

2 posts, 0 answers
  1. Troy Clemons
    Troy Clemons avatar
    69 posts
    Member since:
    Apr 2010

    Posted 26 Feb 2015 Link to this post

    if I have a row selected (this is done to view and image in a rad window) and then
    I hit a column header to sort, the selected index change event is fired
    and the previous selected row fires off and shows the image again.

    how can I stop this from happening.

    Thanks Troy
  2. Konstantin Dikov
    Konstantin Dikov avatar
    1756 posts

    Posted 03 Mar 2015 Link to this post

    Hello Troy,

    The server-side OnSelectedIndexChanged event will fire as soon as a postback occurs (regardless of the initiator). If you are performing a client-side selection, when you sort the grid through a column's header, a postback will occur and the OnSelectedIndexChanged will fire.

    However, if you are setting the EnablePostBackOnRowClick property to true, once you click on a row, the server-side OnSelectedIndexChanged event will fire and when you sort afterwords, the event will not fire a second time.

    Following is a simple example demonstrating that the event will fire only once:
    <telerik:RadGrid runat="server" ID="RadGrid1" OnNeedDataSource="RadGrid1_NeedDataSource" OnSelectedIndexChanged="RadGrid1_SelectedIndexChanged" AllowSorting="true">
        <ClientSettings Selecting-AllowRowSelect="true" EnablePostBackOnRowClick="true"></ClientSettings>

    And the code-behind:
    protected void RadGrid1_NeedDataSource(object sender, GridNeedDataSourceEventArgs e)
        DataTable table = new DataTable();
        table.Columns.Add("ID", typeof(int));
        table.Columns.Add("FirstName", typeof(string));
        table.Columns.Add("LastName", typeof(string));
        table.Columns.Add("Age", typeof(int));
        table.Columns.Add("Date", typeof(DateTime));
        table.Columns.Add("BoolValue", typeof(Boolean));
        for (int i = 0; i < 5; i++)
            table.Rows.Add(i, "FirstName" + i, "LastName" + i, 20 + i, DateTime.Now.AddDays(i), i % 2 == 0);
        (sender as RadGrid).DataSource = table;
    protected void RadGrid1_SelectedIndexChanged(object sender, EventArgs e)

    Hope this helps.

    Konstantin Dikov

    Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.

  3. Telerik UI for ASP.NET Core is out
Back to Top