My issue is I'm trying to have a datagrid (ASP.NET 1.1) to allow editing, along with sorting ASC/DESC via column headers.
When I click "Edit", my SQL query ASC goes to DESC, and vice versa. This happens on Cancel, Paging, Delete, etc...I'm trying to limit the "swap" in the order by criterion only when a header (of Template columns) is clicked.
****************I have this in the HTML:
OnSortCommand="SortDG" AllowSorting="True"
***************Code behind to try to limit only to column headers, but not working:
Private Sub DGActivities_ItemCommand(ByVal source As Object, ByVal e As System.Web.UI.WebControls.DataGridCommandEventArgs) Handles DGActivities.ItemCommand
If e.Item.ItemType = ListItemType.Header Then
If ViewState("DGActGlobalAscDesc") = "" Then
ViewState("DGActGlobalAscDesc") = "ASC"
SwapDirection(ViewState("DGActGlobalAscDesc"))
Else
SwapDirection(ViewState("DGActGlobalAscDesc"))
End If
End If
End Sub
Sub SwapDirection(ByVal viewStateKey As String)
If ViewState(viewStateKey) = "ASC" Then
ViewState(viewStateKey) = "DESC"
ViewState("DGActFieldAscDesc") = "DESC"
Else
ViewState(viewStateKey) = "ASC"
ViewState("DGActFieldAscDesc") = "ASC"
End If
End Sub
When I click "Edit", my SQL query ASC goes to DESC, and vice versa. This happens on Cancel, Paging, Delete, etc...I'm trying to limit the "swap" in the order by criterion only when a header (of Template columns) is clicked.
****************I have this in the HTML:
OnSortCommand="SortDG" AllowSorting="True"
***************Code behind to try to limit only to column headers, but not working:
Private Sub DGActivities_ItemCommand(ByVal source As Object, ByVal e As System.Web.UI.WebControls.DataGridCommandEventArgs) Handles DGActivities.ItemCommand
If e.Item.ItemType = ListItemType.Header Then
If ViewState("DGActGlobalAscDesc") = "" Then
ViewState("DGActGlobalAscDesc") = "ASC"
SwapDirection(ViewState("DGActGlobalAscDesc"))
Else
SwapDirection(ViewState("DGActGlobalAscDesc"))
End If
End If
End Sub
Sub SwapDirection(ByVal viewStateKey As String)
If ViewState(viewStateKey) = "ASC" Then
ViewState(viewStateKey) = "DESC"
ViewState("DGActFieldAscDesc") = "DESC"
Else
ViewState(viewStateKey) = "ASC"
ViewState("DGActFieldAscDesc") = "ASC"
End If
End Sub