Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > ASP.NET and ASP > ASP.NET 2.0 > ASP.NET 2.0 Professional
Password Reminder
Register
Register | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
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 tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
 
 
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old September 4th, 2006, 10:51 AM
Friend of Wrox
 
Join Date: Oct 2005
Location: , , United Kingdom.
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
  #2 (permalink)  
Old September 4th, 2006, 12:36 PM
Authorized User
 
Join Date: Sep 2006
Location: , , India.
Posts: 66
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Hi ,
What Datasource do u use to fill the GridView

  #3 (permalink)  
Old September 4th, 2006, 12:45 PM
Friend of Wrox
 
Join Date: Oct 2005
Location: , , United Kingdom.
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
  #4 (permalink)  
Old September 4th, 2006, 12:58 PM
Authorized User
 
Join Date: Sep 2006
Location: , , India.
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'

  #5 (permalink)  
Old September 4th, 2006, 01:10 PM
Friend of Wrox
 
Join Date: Oct 2005
Location: , , United Kingdom.
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
  #6 (permalink)  
Old September 4th, 2006, 01:33 PM
Authorized User
 
Join Date: Sep 2006
Location: , , India.
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


  #7 (permalink)  
Old September 4th, 2006, 02:27 PM
Friend of Wrox
 
Join Date: Oct 2005
Location: , , United Kingdom.
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
  #8 (permalink)  
Old September 4th, 2006, 09:45 PM
Authorized User
 
Join Date: Sep 2006
Location: , , India.
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.





  #9 (permalink)  
Old September 4th, 2006, 10:14 PM
Authorized User
 
Join Date: Sep 2006
Location: , , India.
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.

  #10 (permalink)  
Old September 5th, 2006, 06:13 AM
Friend of Wrox
 
Join Date: Oct 2005
Location: , , United Kingdom.
Posts: 173
Thanks: 0
Thanked 2 Times in 1 Post
Default

Thanks SriRamaKrishna,

I'll give it a go now.

Rit
 


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


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



All times are GMT -4. The time now is 06:04 AM.


Powered by vBulletin®
Copyright ©2000 - 2019, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.