 |
| 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
|
|
|
|

September 4th, 2006, 10:51 AM
|
|
Friend of Wrox
|
|
Join Date: Oct 2005
Posts: 173
Thanks: 0
Thanked 2 Times in 1 Post
|
|
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
|
|

September 4th, 2006, 12:36 PM
|
|
Authorized User
|
|
Join Date: Sep 2006
Posts: 66
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Hi ,
What Datasource do u use to fill the GridView
|
|

September 4th, 2006, 12:45 PM
|
|
Friend of Wrox
|
|
Join Date: Oct 2005
Posts: 173
Thanks: 0
Thanked 2 Times in 1 Post
|
|
Hi SriRamaKrishna
I use an SQLDataAdapter..
SQLDataAdapter.Fill(myDataSet)... which is databound to my Gridview control.
Manyt hanks
Rit
|
|

September 4th, 2006, 12:58 PM
|
|
Authorized User
|
|
Join Date: Sep 2006
Posts: 66
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Hi, My question is whether u wanto use any other datasource ,or populate grid with XML.What do u mean by 'Without Relying'
|
|

September 4th, 2006, 01:10 PM
|
|
Friend of Wrox
|
|
Join Date: Oct 2005
Posts: 173
Thanks: 0
Thanked 2 Times in 1 Post
|
|
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
|
|

September 4th, 2006, 01:33 PM
|
|
Authorized User
|
|
Join Date: Sep 2006
Posts: 66
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
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
|
|

September 4th, 2006, 02:27 PM
|
|
Friend of Wrox
|
|
Join Date: Oct 2005
Posts: 173
Thanks: 0
Thanked 2 Times in 1 Post
|
|
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
|
|

September 4th, 2006, 09:45 PM
|
|
Authorized User
|
|
Join Date: Sep 2006
Posts: 66
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
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.
|
|

September 4th, 2006, 10:14 PM
|
|
Authorized User
|
|
Join Date: Sep 2006
Posts: 66
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
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.
|
|

September 5th, 2006, 06:13 AM
|
|
Friend of Wrox
|
|
Join Date: Oct 2005
Posts: 173
Thanks: 0
Thanked 2 Times in 1 Post
|
|
Thanks SriRamaKrishna,
I'll give it a go now.
Rit
|
|
 |