|
-
Oct 4th, 2004, 07:28 AM
#1
Thread Starter
Fanatic Member
[Resolved] Two way sorting of datagrid
Im trying to sortmy datagrid two ways and nothing happens, Originally I was sorting it once and sorting my dataview, this worked ok. Now I am trying to sort the datagrid directly and nothing happens.
VB Code:
Function pulldata()
Dim strChnl As String = Trim(lstChnl.SelectedItem.Value)
Dim dsOne As New System.data.DataSet
da.Fill(dsOne, "dtOne")
Dim dvOne As New DataView(dsOne.Tables("dtone"))
dvOne.RowFilter = "CHNL_ID ='" & strChnl & "'"
dgOne.DataSource = dvOne
dgOne.DataBind()
End Function
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
If Not Page.IsPostBack Then
Dim cmdChnl As New System.Data.SqlClient.SqlCommand _
("select top 500 chnl_id from olm_003_all group by chnl_id order by chnl_id", sqlOne)
Dim drchnl As System.Data.SqlClient.SqlDataReader
sqlOne.Open()
drchnl = cmdChnl.ExecuteReader()
lstChnl.DataSource = drchnl
lstChnl.DataTextField = "chnl_ID"
lstChnl.DataBind()
drchnl.Close()
sqlOne.Close()
Else
End If
End Sub
Private Sub lstChnl_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles lstChnl.SelectedIndexChanged
pulldata()
End Sub
Private Sub dgOne_PageIndexChanged(ByVal source As Object, ByVal e As System.Web.UI.WebControls.DataGridPageChangedEventArgs) Handles dgOne.PageIndexChanged
dgOne.CurrentPageIndex = e.NewPageIndex
pulldata()
End Sub
Private Sub dgOne_SortCommand(ByVal source As Object, ByVal e As System.Web.UI.WebControls.DataGridSortCommandEventArgs) Handles dgOne.SortCommand
Dim curSortExpr As String = dgOne.Attributes("SortExpr")
Dim newSortExpr As String = e.SortExpression
If Not (curSortExpr Is Nothing) AndAlso curSortExpr.ToString = e.SortExpression Then
newSortExpr &= " DESC"
End If
dgOne.Attributes("SortExpr") = newSortExpr
pulldata()
End Sub
End Class
Last edited by davebat; Oct 5th, 2004 at 02:18 AM.
-
Oct 5th, 2004, 02:18 AM
#2
Thread Starter
Fanatic Member
sorted, i stored the field and sort order in hidden fields called lastcol and lastorder.
VB Code:
Function pulldata()
Dim strChnl As String = Trim(lstChnl.SelectedItem.Value)
Dim dsOne As New System.data.DataSet
da.Fill(dsOne, "dtOne")
Dim dvOne As New DataView(dsOne.Tables("dtone"))
dvOne.RowFilter = "CHNL_ID ='" & strChnl & "'"
dvOne.Sort = lastCol.Value + " " + lastOrder.Value
dgOne.DataSource = dvOne
dgOne.DataBind()
Label1.Text = sortExpression
End Function
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
If Not Page.IsPostBack Then
Dim cmdChnl As New System.Data.SqlClient.SqlCommand _
("select top 500 chnl_id from olm_003_all group by chnl_id order by chnl_id", sqlOne)
Dim drchnl As System.Data.SqlClient.SqlDataReader
sqlOne.Open()
drchnl = cmdChnl.ExecuteReader()
lstChnl.DataSource = drchnl
lstChnl.DataTextField = "chnl_ID"
lstChnl.DataBind()
drchnl.Close()
sqlOne.Close()
Else
End If
End Sub
Private Sub lstChnl_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles lstChnl.SelectedIndexChanged
pulldata()
End Sub
Private Sub dgOne_PageIndexChanged(ByVal source As Object, ByVal e As System.Web.UI.WebControls.DataGridPageChangedEventArgs) Handles dgOne.PageIndexChanged
dgOne.CurrentPageIndex = e.NewPageIndex
Label1.Text = e.NewPageIndex
pulldata()
End Sub
Public Sub dgOne_SortCommand(ByVal source As Object, ByVal e As System.Web.UI.WebControls.DataGridSortCommandEventArgs) Handles dgOne.SortCommand
Dim sortOrder = "Asc"
If (e.SortExpression.ToString() = lastCol.Value) AndAlso (sortOrder = lastOrder.Value) Then
sortOrder = "Desc"
End If
lastCol.Value = e.SortExpression.ToString()
lastOrder.Value = sortOrder
pulldata()
End Sub
End Class
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|