Solved

sorting on a datagrid

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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

If you're writing a .NET application to connect to an Access .mdb database and use pre-existing queries that require parameters, you've come to the right place! Let's say the pre-existing query(qryCust) in Access takes a Date as a parameter and l…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, Just open a new email message.  In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…
This demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.

759 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

19 Experts available now in Live!

Get 1:1 Help Now