Problem with Sorting Web Datagrid

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
 
J

Joe Fallon

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.
 
G

Guest

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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Members online

No members online now.

Forum statistics

Threads
473,774
Messages
2,569,596
Members
45,143
Latest member
SterlingLa
Top