Wrox Programmer Forums
Go Back   Wrox Programmer Forums > ASP.NET and ASP > ASP.NET 2.0 > ASP.NET 2.0 Professional
|
ASP.NET 2.0 Professional If you are an experienced ASP.NET programmer, this is the forum for your 2.0 questions. Please also see the Visual Web Developer 2005 forum.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the ASP.NET 2.0 Professional section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old September 4th, 2006, 10:51 AM
Friend of Wrox
 
Join Date: Oct 2005
Posts: 173
Thanks: 0
Thanked 2 Times in 1 Post
Default Gridview Sorting Event without a Datasource

Eeek!..

Hi All

In VB.Net, can anyone share with me how to implement Gridview column sorting within relying on using an SQLDatasource control?

I have looked on the Net but cannot locate what I am after.

Many thanks in advance

Rit
__________________
Rit
www.designandonline.co.uk
INSPIRE | CREATE | DELIVER
 
Old September 4th, 2006, 12:36 PM
Authorized User
 
Join Date: Sep 2006
Posts: 66
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Hi ,
What Datasource do u use to fill the GridView

 
Old September 4th, 2006, 12:45 PM
Friend of Wrox
 
Join Date: Oct 2005
Posts: 173
Thanks: 0
Thanked 2 Times in 1 Post
Default

Hi SriRamaKrishna

I use an SQLDataAdapter..

SQLDataAdapter.Fill(myDataSet)... which is databound to my Gridview control.

Manyt hanks

Rit
 
Old September 4th, 2006, 12:58 PM
Authorized User
 
Join Date: Sep 2006
Posts: 66
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Hi, My question is whether u wanto use any other datasource ,or populate grid with XML.What do u mean by 'Without Relying'

 
Old September 4th, 2006, 01:10 PM
Friend of Wrox
 
Join Date: Oct 2005
Posts: 173
Thanks: 0
Thanked 2 Times in 1 Post
Default

Hi SriRamaKrishna

Firstly, thanks for your time.

I don't populate my Gridview using a DataSource control such as SQLDataSource as I databind it to a Dataset which is populated using an SQLConnection and SQLDataAdapter.

I presume I need to change the sort by order within my Dataset???.. if this is right I am not sure where to start.

You will have to excuse me as though I have been around this stuff for a little while I do still struggle in places!

Rit
 
Old September 4th, 2006, 01:33 PM
Authorized User
 
Join Date: Sep 2006
Posts: 66
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Fine Rit ,
There are some steps u must follow if u wanto manually control sorting.

1)u must deselect auto-generate columns in GridView properties.
2) add bound columns.
3) In Bound Column Property
  a)set the databinding expression in datafield property
  b)Give a name for sortExression

4)U create Dataview from the dataset.Because dataview has good methods for sorting and filtering.

5) then Bind The Dataview to the Grid Control .

Try It Rit


 
Old September 4th, 2006, 02:27 PM
Friend of Wrox
 
Join Date: Oct 2005
Posts: 173
Thanks: 0
Thanked 2 Times in 1 Post
Default

Hi SriRamaKrishna

I have followed your instructions. But do I have to do something within the Gridview's sorting event?.. I get the following error:

The GridView 'GridView1' fired event Sorting which wasn't handled.

Many thanks
Rit
 
Old September 4th, 2006, 09:45 PM
Authorized User
 
Join Date: Sep 2006
Posts: 66
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Hai Rit,
   Ok , First u have to set allsorting property of gridview to tru.U will see the Blue Link in header of gridView.

  Dataview view has sort propery .Which u must give the column name to sort.
eg.
DataSet ds = new Dataset;
DA.fille(ds); //filling dataset
Dataview dv= ds.Tables[0].defaultView;
dv.Sort="...ColumnName..."
Then Bind GridView to DV

eg.
Gridview.Datasource=dv

There are 2 sorting events for GridView namely sorting and sorted.U should bind the Dataview in that event.

So.When ever we click the column header link ,Sorting event is fired.In That Event we sort the dataview then again bing it to gridview.

If There is further Doubt,Let Me Know ,I will send the code.





 
Old September 4th, 2006, 10:14 PM
Authorized User
 
Join Date: Sep 2006
Posts: 66
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Hi, Its possible to know which column is cliclked by sorting event's EventArg.So we may use it fro dataview's sort property

eg.
Dataview.Sort=e.SortExpression

Remember : The Sortexpression name u have given while creating the bound column in GridView Must be the name of column.

 
Old September 5th, 2006, 06:13 AM
Friend of Wrox
 
Join Date: Oct 2005
Posts: 173
Thanks: 0
Thanked 2 Times in 1 Post
Default

Thanks SriRamaKrishna,

I'll give it a go now.

Rit





Similar Threads
Thread Thread Starter Forum Replies Last Post
Sorting GridView with a Collection as DataSource+ danielpilon C# 7 June 10th, 2008 04:20 PM
Disp Footer even no record in GridView Datasource mallikalapati ASP.NET 2.0 Professional 1 March 19th, 2008 02:23 AM
chapter about object datasource and gridview? asptwodev BOOK: ASP.NET 2.0 Instant Results ISBN: 978-0-471-74951-6 1 November 2nd, 2007 12:53 PM
Gridview for inser,update without using datasource karthikeyan_pa ASP.NET 2.0 Professional 0 September 4th, 2007 07:58 AM
GridView DataSource Abbas C# 2005 0 November 28th, 2006 02:54 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.