Sorting Possible?

N

Nick C

Hi

I am trying to sort my gridview ? What is the best way to do this?

th Nick

<%@ Page Language="VB" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"

"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<script runat="server">

Public Class person

Dim _name As String

Public Property Name()

Get

Return _name

End Get

Set(ByVal value)

_name = value

End Set

End Property


Dim _address As String

Public Property address()

Get

Return _address

End Get

Set(ByVal value)

_address = value

End Set

End Property









End Class

Public Class PersonCollection : Inherits CollectionBase

Sub New()

MyBase.New()

End Sub

Public Property item(ByVal i As Integer)

Get

Return Me.List(i)

End Get

Set(ByVal value)

Me.List(i) = value

End Set

End Property

Public Sub add(ByVal item As person)

Me.List.Add(item)

End Sub

End Class

Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles
Me.Load

If Not IsPostBack Then

GridView2.DataSource = source()

GridView2.DataBind()

End If



End Sub

Protected Function source() As PersonCollection

Dim objPersonCollection As New PersonCollection

Dim intnumber As Integer = 3

For a As Integer = 0 To 3

Dim objPerson As New person

objPerson.Name = "Name" + a.ToString

objPerson.address = "Street" + intnumber.ToString()

objPersonCollection.add(objPerson)


intnumber -= 1

Next

Return objPersonCollection

End Function





Protected Sub GridView2_Sorting(ByVal sender As Object, ByVal e As
System.Web.UI.WebControls.GridViewSortEventArgs)

GridView2.DataSource = source()

GridView2.DataBind()

End Sub

</script>

<html xmlns="http://www.w3.org/1999/xhtml">

<head id="Head1" runat="server">

<title></title>

</head>

<body>

<form id="form1" runat="server">

<div>

<asp:GridView ID="GridView2" runat="server" AllowSorting="true"
AutoGenerateColumns="false"

OnSorting="GridView2_Sorting">

<Columns>

<asp:BoundField HeaderText="name" DataField="Name" />

<asp:BoundField HeaderText="Address" DataField="Address" />

</Columns>

</asp:GridView>

</div>

</form>

</body>

</html>
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,994
Messages
2,570,223
Members
46,815
Latest member
treekmostly22

Latest Threads

Top