Results 1 to 2 of 2

Thread: [Resolved] Two way sorting of datagrid

Threaded View

  1. #1

    Thread Starter
    Fanatic Member davebat's Avatar
    Join Date
    Dec 2002
    Posts
    727

    Resolved [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:
    1. Function pulldata()
    2.         Dim strChnl As String = Trim(lstChnl.SelectedItem.Value)
    3.         Dim dsOne As New System.data.DataSet
    4.         da.Fill(dsOne, "dtOne")
    5.         Dim dvOne As New DataView(dsOne.Tables("dtone"))
    6.         dvOne.RowFilter = "CHNL_ID ='" & strChnl & "'"
    7.         dgOne.DataSource = dvOne
    8.         dgOne.DataBind()
    9.     End Function
    10.  
    11.  
    12.     Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
    13.         If Not Page.IsPostBack Then
    14.             Dim cmdChnl As New System.Data.SqlClient.SqlCommand _
    15.             ("select top 500 chnl_id from olm_003_all group by chnl_id order by chnl_id", sqlOne)
    16.             Dim drchnl As System.Data.SqlClient.SqlDataReader
    17.             sqlOne.Open()
    18.             drchnl = cmdChnl.ExecuteReader()
    19.             lstChnl.DataSource = drchnl
    20.             lstChnl.DataTextField = "chnl_ID"
    21.             lstChnl.DataBind()
    22.             drchnl.Close()
    23.             sqlOne.Close()
    24.         Else
    25.         End If
    26.     End Sub
    27.  
    28.  
    29.     Private Sub lstChnl_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles lstChnl.SelectedIndexChanged
    30.         pulldata()
    31.     End Sub
    32.     Private Sub dgOne_PageIndexChanged(ByVal source As Object, ByVal e As System.Web.UI.WebControls.DataGridPageChangedEventArgs) Handles dgOne.PageIndexChanged
    33.         dgOne.CurrentPageIndex = e.NewPageIndex
    34.         pulldata()
    35.     End Sub
    36.  
    37.  
    38.     Private Sub dgOne_SortCommand(ByVal source As Object, ByVal e As System.Web.UI.WebControls.DataGridSortCommandEventArgs) Handles dgOne.SortCommand
    39.         Dim curSortExpr As String = dgOne.Attributes("SortExpr")
    40.         Dim newSortExpr As String = e.SortExpression
    41.  
    42.         If Not (curSortExpr Is Nothing) AndAlso curSortExpr.ToString = e.SortExpression Then
    43.             newSortExpr &= " DESC"
    44.         End If
    45.         dgOne.Attributes("SortExpr") = newSortExpr
    46.         pulldata()
    47.     End Sub
    48. End Class
    Last edited by davebat; Oct 5th, 2004 at 02:18 AM.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width