sorting on a datagrid

Hi experts,
I am trying to sort on a datagrid.

i have performed these steps, but how come i can't still sort on the grid.
==================================================================================
   Public Property sortCriteria() As String
        Get
            Return CStr(viewstate("sortCriteria"))
        End Get
        Set(ByVal Value As String)
            ViewState("sortCriteria") = Value
        End Set
    End Property
===========================================================================
    ' Holds the direction to be sorted...
    Public Property sortDir() As String
        Get
            Return CStr(viewstate("sortDir"))
        End Get
        Set(ByVal Value As String)
            ViewState("sortDir") = Value
        End Set
    End Property
============================================================================================
    Sub dgusers_Sort(ByVal sender As Object, ByVal e As DataGridSortCommandEventArgs) Handles dgUsers.SortCommand
        ' Check to see if the column we clicked on is the current column defined
        ' in the sortCriteria property.
        If Me.sortCriteria = e.SortExpression Then
            If Me.sortDir = "desc" Then
                Me.sortDir = "asc"
            Else
                Me.sortDir = "desc"
            End If
        End If
        ' Assign the column clicked to the sortCriteria property
        Me.sortCriteria = e.SortExpression
        ' Now call the procedure to re-display the Data Grid
    End Sub
============================================================================================
#Region "LoadData Subroutine "
    Private Sub LoadData()
        'Calls the GetAllUser Function
        dgUsers.DataSource = LicenseDB.GetAllUser(Me.sortDir, Me.sortCriteria)
        dgUsers.DataBind()
    End Sub
#End Region
==========================================================
then this is the getalluser function


    'fills the datagrid with details
    Public Shared Function GetAllUser(ByVal sortDir As String, ByVal sortCriteria As String) As ArrayList
        Dim arr As New ArrayList
        Dim DBConnection As SqlConnection = Connection()
        DBConnection.Open()
        Dim cmdLicense As SqlCommand = New SqlCommand("SPR_GETALL_USERPROFILE", DBConnection)
        cmdLicense.CommandType = CommandType.StoredProcedure
        Try
            Dim drlicense As SqlDataReader
            drlicense = cmdLicense.ExecuteReader()
            While drlicense.Read()
                Dim userProfile As New UserProfile
                userProfile.userProfileID = DataUtil.IsNull(drlicense.Item("userProfileID"), "")
                userProfile.firstName = DataUtil.IsNull(drlicense.Item("firstName"), "")
                userProfile.lastName = DataUtil.IsNull(drlicense.Item("lastName"), "")
                userProfile.address1 = DataUtil.IsNull(drlicense.Item("address1"), "")
                userProfile.address2 = DataUtil.IsNull(drlicense.Item("address2"), "")
                userProfile.city = DataUtil.IsNull(drlicense.Item("city"), "")
                userProfile.state = DataUtil.IsNull(drlicense.Item("state"), "")
                userProfile.zip = DataUtil.IsNull(drlicense.Item("zip"), "")
                userProfile.email = DataUtil.IsNull(drlicense.Item("email"), "")
                userProfile.phone = DataUtil.IsNull(drlicense.Item("phone"), "")
                ' userProfile.employeeflag = DataUtil.IsNull(drlicense.Item("employeeflag"), "")
                userProfile.employeeflag = DataUtil.IsNull(drlicense.Item("employee_Non_employee"), "")
                ' userProfile.employeeflag = DataUtil.IsNull(drlicense.Item("employeeflag"), 0)
                userProfile.username = DataUtil.IsNull(drlicense.Item("username"), "")
                userProfile.password = DataUtil.IsNull(drlicense.Item("password"), "")
                arr.Add(userProfile)
            End While
            Return arr
        Finally
            DBConnection.Close()
        End Try
    End Function
============================================================
CREATE PROCEDURE dbo.SPR_GETALL_USERPROFILE
@SortColumn varchar(255),
@Direction varchar(10)
AS

declare @SQL varchar(8000)
 BEGIN
SELECT  @SQL = 'SELECT          
           userLogin.username,
           userLogin.password,
           userProfile.userProfileID,
           userProfile.firstName,
           userProfile.lastName,
           userProfile.address1,
           userProfile.address2,
           userProfile.city,
           userProfile.state,
           userProfile.zip,
           userProfile.email,
           userProfile.phone,
           userProfile.employeeflag,
         case employeeflag when 1 then "employee" else "Non employee" end as employee_Non_employee
FROM       userLogin INNER JOIN
           userProfile ON userLogin.userProfileID = userProfile.userProfileID
            ORDER BY ' + str(@SortColumn) + '  ' + @Direction
exec(@SQL)  
end
GO


how do i get my sort functionality

thanks


SirReadAlotAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

piyush_soniCommented:
I can see two mistakes if the above things are provided as they are.
First of all, in the Sub dgusers_Sort, at the place where this comment is written - " ' Now call the procedure to re-display the Data Grid" , Just call your Subroutine LoadData().

Secondly, in the Function GetAllUserData, I can't see anywhere the parameters required by the SP being passed through the code.

Just pass the parameters @SortColumn and @Direction to SPR_GETALL_USERPROFILE by your code.
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
SirReadAlotAuthor Commented:
thanks, i will take a look tomorrow
0
SirReadAlotAuthor Commented:
i have do
this
 'fills the datagrid with details
    Public Shared Function GetAllUser(ByVal sortCriteria As String, ByVal sortDir As String) As ArrayList
        Dim arr As New ArrayList
        Dim DBConnection As SqlConnection = Connection()
        DBConnection.Open()
        Dim cmdLicense As SqlCommand = New SqlCommand("SPR_GETALL_USERPROFILE", DBConnection)
        cmdLicense.CommandType = CommandType.StoredProcedure
        cmdLicense.Parameters.Add("@SortColumn", sortCriteria)
        cmdLicense.Parameters.Add("@Direction", sortDir)
        Try
            Dim drlicense As SqlDataReader
            drlicense = cmdLicense.ExecuteReader()
            While drlicense.Read()
                Dim userProfile As New UserProfile
                userProfile.userProfileID = DataUtil.IsNull(drlicense.Item("userProfileID"), "")
                userProfile.firstName = DataUtil.IsNull(drlicense.Item("firstName"), "")
                userProfile.lastName = DataUtil.IsNull(drlicense.Item("lastName"), "")
                userProfile.address1 = DataUtil.IsNull(drlicense.Item("address1"), "")
                userProfile.address2 = DataUtil.IsNull(drlicense.Item("address2"), "")
                userProfile.city = DataUtil.IsNull(drlicense.Item("city"), "")
                userProfile.state = DataUtil.IsNull(drlicense.Item("state"), "")
                userProfile.zip = DataUtil.IsNull(drlicense.Item("zip"), "")
                userProfile.email = DataUtil.IsNull(drlicense.Item("email"), "")
                userProfile.phone = DataUtil.IsNull(drlicense.Item("phone"), "")
                ' userProfile.employeeflag = DataUtil.IsNull(drlicense.Item("employeeflag"), "")
                userProfile.employeeflag = DataUtil.IsNull(drlicense.Item("employee_Non_employee"), "")
                ' userProfile.employeeflag = DataUtil.IsNull(drlicense.Item("employeeflag"), 0)
                userProfile.username = DataUtil.IsNull(drlicense.Item("username"), "")
                userProfile.password = DataUtil.IsNull(drlicense.Item("password"), "")
                arr.Add(userProfile)
            End While
            Return arr
        Finally
            DBConnection.Close()
        End Try
    End Function

but it says that the @sortcolumn is not provided
0
piyush_soniCommented:
Hi, so finally could you solve your problem ? I can see that you have accepted my answer.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Visual Basic.NET

From novice to tech pro — start learning today.