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

RadToolBarSplitButton inside RadGrid not persisted

4 Answers 55 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Massimiliano
Top achievements
Rank 1
Massimiliano asked on 18 Jul 2013, 11:36 AM
I have a toolbar inside my CommandItem in RadGrid.
I'm able to correctly bubble events or fire custom events in the ItemCommand event.
The issue I'm facing is with RadToolBarSplitButton not persisting the button pressed after grid rebind.
For example one of my SplitButtons in the dropdown removes all filters like that

Protected Sub RadGrid1_ItemCommand(ByVal source As Object, ByVal e As GridCommandEventArgs) Handles RadGrid1.ItemCommand
            Select Case e.CommandName
                Case "ClearFilters"
                    For Each column As GridColumn In RadGrid1.MasterTableView.Columns
                        column.CurrentFilterFunction = GridKnownFunction.NoFilter
                        column.CurrentFilterValue = String.Empty
                    Next
                    RadGrid1.MasterTableView.FilterExpression = String.Empty
                    RadGrid1.MasterTableView.Rebind()
            End Select
End Sub

I've tryed to access the bar and set the defaultindex to persist the choice but that is overridden in the itemcreated event fired again after rebind. Any hint other than persisintg the choice somewhere (session/viewstate/cookie) and reading it in the ItemCreated event? Shouldn't this already be persisted (and restored) by default somewhere in cookie/viewstate/controlstate?. If this doesn't happens in a RadGrid/ItemCommand implementation how could I read the default persistence mechanism in the ItemCreated event without reinventing the wheel with my custom persistance?
What I tryed (with no success) is this:

        Protected Sub RadGrid1_ItemCommand(ByVal source As Object, ByVal e As GridCommandEventArgs) Handles RadGrid1.ItemCommand
            Select Case e.CommandName
                Case "ClearFilters"
                    Dim toolbar As RadToolBar = DirectCast(e.CommandSource, RadToolBar)
                    Dim button As RadToolBarSplitButton = DirectCast(toolbar.FindItemByText("Ricerca"), RadToolBarSplitButton)
                    button.EnableDefaultButton = True
                    button.DefaultButtonIndex = 2
 
                    For Each column As GridColumn In RadGrid1.MasterTableView.Columns
                        column.CurrentFilterFunction = GridKnownFunction.NoFilter
                        column.CurrentFilterValue = String.Empty
                    Next
                    RadGrid1.MasterTableView.FilterExpression = String.Empty
                    RadGrid1.MasterTableView.Rebind()
              End Select
End Sub

EDIT: if I bind RebindGridCommandName to the button, instead of my custom command (and in this case rebinding happens the same since the command is for refreshing the grid) this button is persisted without any addittional code handling. With my custom command intercepted in the ItemCommand event this doesn't happen

4 Answers, 1 is accepted

Sort by
0
Kostadin
Telerik team
answered on 23 Jul 2013, 07:10 AM
Hello Massimiliano,

I am afraid that the selected button is not persisted through postback and you have to do it manually. I prepared a small sample where I demonstrates a possible approach to persist the selected button. Please give it a try and let me know about the result.

Regards,
Kostadin
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
Massimiliano
Top achievements
Rank 1
answered on 23 Jul 2013, 07:21 PM
Thank you Kostadin you were precious. I not only think Telerik controls are the best but support also in this forum is first class!!
Only downside I think the AJAX suite is a bit too pricey for very small developers. If it was a one-time fee it could even be a no brainer but as a yearly fee to access upgrades it really becomes pricey for very small biz.
0
Massimiliano
Top achievements
Rank 1
answered on 27 Jul 2013, 09:18 AM
Thank you Kostadin I've been able to check your files only today and the solution is what I had in mind for custom persistance of the splitbutton.
The only thing I was missing was to do it in the PreRender event, that's why my first tests didn't gave appreciable results.
Very helpful as always!

BTW Shouldn't this be handled automatically like in any other controls (splitter or tabstrip)? It's just the grid that breaks it and as a standalone control the toolbar handles it automatically?
0
Kostadin
Telerik team
answered on 31 Jul 2013, 02:05 PM
Hi Massimiliano,

I am afraid that this could not be handled automatically, because the state of the current chosen item of the RadToolBarSplitButton is not save at the ViewState at that moment. When you call Rebind() method the RadGrid recreate the last saved state of the button from the ViewState which is the initial chosen item. In order to show the last chosen item you have explicitly save the state of the Button into the ViewState.

Regards,
Kostadin
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.
Tags
Grid
Asked by
Massimiliano
Top achievements
Rank 1
Answers by
Kostadin
Telerik team
Massimiliano
Top achievements
Rank 1
Share this question
or