Solved

sorting on a datagrid

Posted on 2007-03-27
4
212 Views
Last Modified: 2010-04-23
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


0
Comment
Question by:SirReadAlot
  • 2
  • 2
4 Comments
 
LVL 2

Accepted Solution

by:
piyush_soni earned 500 total points
ID: 18801496
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
 

Author Comment

by:SirReadAlot
ID: 18801872
thanks, i will take a look tomorrow
0
 

Author Comment

by:SirReadAlot
ID: 18806685
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
 
LVL 2

Expert Comment

by:piyush_soni
ID: 18815581
Hi, so finally could you solve your problem ? I can see that you have accepted my answer.
0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction As chip makers focus on adding processor cores over increasing clock speed, developers need to utilize the features of modern CPUs.  One of the ways we can do this is by implementing parallel algorithms in our software.   One recent…
Parsing a CSV file is a task that we are confronted with regularly, and although there are a vast number of means to do this, as a newbie, the field can be confusing and the tools can seem complex. A simple solution to parsing a customized CSV fi…
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…

830 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question