Problem with Sorting Web Datagrid

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hi There

I have a datagrid with a Select(LinkButton) Column followed by several Bound
Columns.

I have enabled the columns to sort and created the correct event handler (I
think) - however the crux of my problem is that when I click on one of the
column headers to sort by it the ItemCommand fires rather than the
SortCommand.

in the .aspx file I have:
OnItemCommand="SalesGroupInitial_ItemCommand"
OnSortCommand="SalesGroupInitial_SortCommand"

which correlate to the .aspx.vb file (I also have an OnItemDatabound event
if that is of any significance)

I have not included the code at this juncture as it is a flat case of the
wrong event firing when I click the Column Header

Any ideas would be very much appreciated

Stuart
 
I think the ItemCommand handler will run even when you sort. (It does when
you page.)

Protected Sub SalesGroupInitial_ItemCommand(ByVal source As Object, ByVal e
As DataGridCommandEventArgs)
'Grid paging causes this event to fire (among others) and
e.Item.ItemIndex=-1 so we should avoid an error by coding for this case.

If e.Item.ItemIndex >= 0 Then
'now do stuff
End If

End Sub

Check that your Sort signature includes a Handles statement.
Sometimes they "disappear" - if you re-name the grid in the .aspx they will
go away and you have to manually add them back.
 
Spot on !

Thanks very much Joe

Joe Fallon said:
I think the ItemCommand handler will run even when you sort. (It does when
you page.)

Protected Sub SalesGroupInitial_ItemCommand(ByVal source As Object, ByVal e
As DataGridCommandEventArgs)
'Grid paging causes this event to fire (among others) and
e.Item.ItemIndex=-1 so we should avoid an error by coding for this case.

If e.Item.ItemIndex >= 0 Then
'now do stuff
End If

End Sub

Check that your Sort signature includes a Handles statement.
Sometimes they "disappear" - if you re-name the grid in the .aspx they will
go away and you have to manually add them back.
 
Back
Top