473,406 Members | 2,293 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,406 software developers and data experts.

Sorting Possible?

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>
Feb 4 '07 #1
1 1113
See

http://www.gridviewguy.com/ArticleDe...?articleID=203
PS

CollectionBase is ... 1.1'ish.

Try

using System;
using System.Collections.Generic;
using System.Text;

public class PersonCollection :
System.Collections.Generic.Collection
<Person>
{
}


"Nick C" <be****@gmail.comwrote in message
news:%2****************@TK2MSFTNGP03.phx.gbl...
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>


Feb 8 '07 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: praba kar | last post by:
Dear All, I am new to Python. I am in need of some sorting functions (eg) numerical sorting functions and alphapetical sorting functions. I have searched through net But I cannot find any...
9
by: p0wer | last post by:
Let's suppose I have this sample document: <root> <entry id="1" <date>2003-08-03</date> <param_1>5</param_1> <param_2>10</param_2> </entry> <entry id="2"> ...
17
by: Matt Kruse | last post by:
I'm looking for the best JS/CSS solution to add functionality to tables. The only browser which needs to be supported is IE5.5+, but no activeX can be used. to be able to do: - Fixed header row...
2
by: Alan Searle | last post by:
I find that I can display structured data very nicely using XML with an XSL template. As an extra 'goodie', I would like to give users the ability to sort that data (for example with a button...
0
by: Simon Gregory | last post by:
I am currently attempting to figure out how the new databinding stucture works in ASP.NET 2.0 after working with v1.0 & v1.1 for several years. It seems that if you wish to do set up databinding...
25
by: Dan Stromberg | last post by:
Hi folks. Python appears to have a good sort method, but when sorting array elements that are very large, and hence have very expensive compares, is there some sort of already-available sort...
25
by: Allie | last post by:
How would I go about sorting this structure by title? typedef struct { char author; char title; char code; int hold; int loan; } LIBRARY;
4
by: FBM | last post by:
Hi, I am working on a program that simulates one of the elements of ATM. The simulation stores events which occurs every some milliseconds for a certain amount of time. Every time that an event...
10
by: Sjaakie | last post by:
Hi, I'm, what it turns out to be, fooling around with 3-tier design. At several websites people get really enthusiastic about using custom dataobjects instead of datasets/-tables. While trying to...
4
by: Ambica Jain | last post by:
Hi, I want custom sorting on some of the columns in the datagrid. And i am able to do the same by overriding MouseDown event. However, i need to rebind my datatable to reflect the changes in...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.