Solved

sorting on a datagrid

Posted on 2007-03-27
4
204 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Article by: jpaulino
XML Literals are a great way to handle XML files and the community doesn’t use it as much as it should.  An XML Literal is like a String (http://msdn.microsoft.com/en-us/library/system.string.aspx) Literal, only instead of starting and ending with w…
It’s quite interesting for me as I worked with Excel using vb.net for some time. Here are some topics which I know want to share with others whom this might help. First of all if you are working with Excel then you need to Download the Following …
In this video I am going to show you how to back up and restore Office 365 mailboxes using CodeTwo Backup for Office 365. Learn more about the tool used in this video here: http://www.codetwo.com/backup-for-office-365/ (http://www.codetwo.com/ba…
CodeTwo Sync for iCloud (http://www.codetwo.com/sync-for-icloud?sts=6554) automatically synchronizes your Outlook 2016, 2013, 2010 or 2007 folders with iCloud folders available via iCloud Control Panel. This lets you automatically sync them with…

911 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

Need Help in Real-Time?

Connect with top rated Experts

21 Experts available now in Live!

Get 1:1 Help Now