I've already posted this in the asp forum, and other asp.net forums on the
net with no luck...
I've got a data grid, with paging, and sorting allowed. I can find loads of
examples, and have previous done this, when generating all the data from my
database at run time, progmatically.
Now I'm trying to do it through the design editor, using datasets instead of
dataviews, etc...
is what i'm doing below the wrong approach when attempting this in a "design
time" fashion?
the paging works fine, and i get links correctly for clicking on the title
to sort, but sorting does not work, why?
' ---------- CODE START
' other initialization and delcarations here...
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
If Not Page.IsPostBack Then
' change the page title
Label1.Text = "BIF II ( Avenue ) Logger on " +
System.Environment.MachineName + ". ...Sorting currently not working..."
' Put user code here to initialize the data source
sqldataadapterLogger.Fill(DataSetLogger)
DataGrid1.DataSource = DataSetLogger.AvenueLog.DefaultView
DataGrid1.DataBind()
Session("dataset") = DataSetLogger
Session("pageindex") = 0
Session("sortcolumn") = Nothing
Session("sortascend") = False
End If
End Sub
Private Sub BindData()
DataSetLogger = Session("dataset")
Dim currentPageIndex As Integer = Session("pageindex")
Dim currentSortColumn As String = Session("sortcolumn")
Dim dv As DataView = DataSetLogger.AvenueLog.DefaultView
' apply sorting
If (Not currentSortColumn Is Nothing) Then
If (Session("sortascend") = True) Then
dv.Sort = currentSortColumn + " ASC"
Else
dv.Sort = currentSortColumn + " DESC"
End If
' ************************************************** **
' this label1 is a title, and correctly displays
' the column i click on with the appending ASC/DESC
' to prove the code hits here, and that the sort is
' being set correctly.
' ************************************************** **
Label1.Text = dv.Sort
End If
' apply current page
DataGrid1.CurrentPageIndex = currentPageIndex
' bind data
DataGrid1.DataSource = dv
DataGrid1.DataBind()
End Sub
Private Sub DataGrid1_PageIndexChanged(ByVal source As Object, ByVal e _
As System.Web.UI.WebControls.DataGridPageChangedEvent Args) _
Handles DataGrid1.PageIndexChanged
Session("pageindex") = e.NewPageIndex
BindData()
End Sub
Private Sub DataGrid1_SortCommand(ByVal source As Object, _
ByVal e As System.Web.UI.WebControls.DataGridSortCommandEvent Args)
_
Handles DataGrid1.SortCommand
Session("sortascend") = Not Session("sortascend")
Session("sortcolumn") = e.SortExpression
BindData()
End Sub
' ------------ CODE END
Thanks for your time and help,
in anticipation.
Daniel.