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




Reply With Quote