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

Deselect the last selected row won't fire "SelectedIndexChanged" event.

3 Answers 247 Views
Grid
This is a migrated thread and some comments may be shown as answers.
LamKhoa
Top achievements
Rank 1
LamKhoa asked on 09 Aug 2012, 03:23 PM

Hi,

When there is MultipleRowSelection = true & EnablePostBackOnRowClick = true, the event "SelectedIndexChanged" is fired everytime I check/uncheck row. That's great.  However, When I tried to uncheck the last selected row (so that now the grid has no row selected), the event "SelectedIndexChange" didn't fire.

I found a similiar post in here:
http://www.telerik.com/community/forums/aspnet-ajax/grid/radgrid-deselect-not-always-firing-selectedindexchanged.aspx

in which they suggested work-around using Javascript:

 

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

//Code-Behind

PatientList_Grid.ClientSettings.ClientEvents.OnRowClick = "RowClick";

 

PatientList_Grid.ClientSettings.ClientEvents.OnRowDeselecting = "RowClick";



 

 

 

private void Grid_PatientList_SelectedIndexChanged(object sender, EventArgs e) 
{
       RadGrid grd = sender as RadGrid;
       int SelectedCount = grd.SelectedItem.Count;
       lbl_DIsplay.Text = "Number of Item Selected: " + SelectedCount;
}


I did it as above and now the event "SelectedIndexChanged" does fire on deselecting last row. But, in the "SelectedIndexChanged" event, the grid show that it still have one item selected:

 


It still show up as 1, even though, you see, since the last selected has been deselected, it should be 0.

I'm using the latest version of Telerik AJAX control.

Thanks

Lamk.

3 Answers, 1 is accepted

Sort by
0
Wired_Nerve
Top achievements
Rank 2
answered on 03 Jun 2013, 10:24 PM
Any luck on this?
0
Viktor Tachev
Telerik team
answered on 06 Jun 2013, 02:45 PM
Hello,

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. Thus the text of the label is not changed and you are seeing the last value.

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.

Similar approach could be used if you select rows from the Grid with buttons. In this case your logic would be placed in a Button event.

Another approach would be to use server-side selection. This way the OnSelectedIndexChanged event will be fired also when deselecting the last selected row.

I hope this information is useful to you.

Regards,
Viktor Tachev
Telerik
If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to the blog feed now.
0
Wired_Nerve
Top achievements
Rank 2
answered on 07 Jun 2013, 01:51 PM
I have finally figured it out, thanks for the advice.
Tags
Grid
Asked by
LamKhoa
Top achievements
Rank 1
Answers by
Wired_Nerve
Top achievements
Rank 2
Viktor Tachev
Telerik team
Share this question
or