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("sortCriter
ia"))
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 DataGridSortCommandEventAr
gs) 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.so
rtDir, 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_USE
RPROFILE",
DBConnection)
cmdLicense.CommandType = CommandType.StoredProcedur
e
Try
Dim drlicense As SqlDataReader
drlicense = cmdLicense.ExecuteReader()
While drlicense.Read()
Dim userProfile As New UserProfile
userProfile.userProfileID = DataUtil.IsNull(drlicense.
Item("user
ProfileID"
), "")
userProfile.firstName = DataUtil.IsNull(drlicense.
Item("firs
tName"), "")
userProfile.lastName = DataUtil.IsNull(drlicense.
Item("last
Name"), "")
userProfile.address1 = DataUtil.IsNull(drlicense.
Item("addr
ess1"), "")
userProfile.address2 = DataUtil.IsNull(drlicense.
Item("addr
ess2"), "")
userProfile.city = DataUtil.IsNull(drlicense.
Item("city
"), "")
userProfile.state = DataUtil.IsNull(drlicense.
Item("stat
e"), "")
userProfile.zip = DataUtil.IsNull(drlicense.
Item("zip"
), "")
userProfile.email = DataUtil.IsNull(drlicense.
Item("emai
l"), "")
userProfile.phone = DataUtil.IsNull(drlicense.
Item("phon
e"), "")
' userProfile.employeeflag = DataUtil.IsNull(drlicense.
Item("empl
oyeeflag")
, "")
userProfile.employeeflag = DataUtil.IsNull(drlicense.
Item("empl
oyee_Non_e
mployee"),
"")
' userProfile.employeeflag = DataUtil.IsNull(drlicense.
Item("empl
oyeeflag")
, 0)
userProfile.username = DataUtil.IsNull(drlicense.
Item("user
name"), "")
userProfile.password = DataUtil.IsNull(drlicense.
Item("pass
word"), "")
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
Start Free Trial