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

Grid Sort Event

1 Answer 172 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Troy Clemons
Top achievements
Rank 1
Troy Clemons asked on 26 Feb 2015, 05:07 PM
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

1 Answer, 1 is accepted

Sort by
0
Konstantin Dikov
Telerik team
answered on 03 Mar 2015, 12:56 PM
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>
</telerik:RadGrid>

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.


Regards,
Konstantin Dikov
Telerik
 

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.

 
Tags
Grid
Asked by
Troy Clemons
Top achievements
Rank 1
Answers by
Konstantin Dikov
Telerik team
Share this question
or