473,569 Members | 2,691 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

GridView sorting

I have a vb.net 2.0 app that is loading a GridView with a DataSource that is
returned from a function.

The definitions in the function are:

Dim ReportDS As DataSet = New DataSet
Dim ReportTable As System.Data.Dat aTable = New
System.Data.Dat aTable("SendTo" )

The ReportTable is populated row by row by data gotten back from the
Exchange server.

I then set ReportDS.Tables .Add(ReportTabl e) and return ReportDS

I then set GridView.DataSo urce = ReportDS()

This displays exactly as I want it to.

The question is how do I enable sorting on the GridView where it will
actually sort? Setting AllowSorting="T rue" causes a post back, but no
sorting occurs. What is the optimal way to be able to enable sorting here?

Thanks.

Apr 14 '07 #1
4 11134
Hi Gerhard,
When you set the datasource of the GridView to a dataset or a datatable,
actually this is what happens.
Considering your case : if you write this

Dim ReportTable As System.Data.Dat aTable = New System.Data.Dat aTable
"SendTo")
GridView.DataSo urce = ReportTable

this happens
GridView.DataSo urce = ReportTable.Def aultView

The datasource is actually set to a DataView not a table or DataSet. Paging
and sorting is done on DataView.

To accomplish what you want you can do this :
DataView dv = new DataView(Report Table);
dv.Sort = " Name ASC"; or dv.Sort= "Country DESC"; etc
GridView.DataSo urce = dv;

I hope this helps. In case of any difficult feel free to get back.

--
Regards,
Tushar
MCTS - .NET 2.0 Web App
"Gerhard" wrote:
I have a vb.net 2.0 app that is loading a GridView with a DataSource that is
returned from a function.

The definitions in the function are:

Dim ReportDS As DataSet = New DataSet
Dim ReportTable As System.Data.Dat aTable = New
System.Data.Dat aTable("SendTo" )

The ReportTable is populated row by row by data gotten back from the
Exchange server.

I then set ReportDS.Tables .Add(ReportTabl e) and return ReportDS

I then set GridView.DataSo urce = ReportDS()

This displays exactly as I want it to.

The question is how do I enable sorting on the GridView where it will
actually sort? Setting AllowSorting="T rue" causes a post back, but no
sorting occurs. What is the optimal way to be able to enable sorting here?

Thanks.
Apr 15 '07 #2
Thanks. This helped alot!

One last question. Everything is working fine on this, except for the sort
on one column. This column is populate with a Date value as follows:

ReportTable.Col umns.Add("Date" )

Dim dateReceived As Date = CDate(....)

workRow("Date") = dateReceived

dv = New DataView(Report Table)
dv.Sort = "Date Desc"

This sorts, but sorts by the string value of the date instead of the date.

How can I get it to sort by date value instead of the string value?

Thanks.

"Tushar" wrote:
Hi Gerhard,
When you set the datasource of the GridView to a dataset or a datatable,
actually this is what happens.
Considering your case : if you write this

Dim ReportTable As System.Data.Dat aTable = New System.Data.Dat aTable
"SendTo")
GridView.DataSo urce = ReportTable

this happens
GridView.DataSo urce = ReportTable.Def aultView

The datasource is actually set to a DataView not a table or DataSet. Paging
and sorting is done on DataView.

To accomplish what you want you can do this :
DataView dv = new DataView(Report Table);
dv.Sort = " Name ASC"; or dv.Sort= "Country DESC"; etc
GridView.DataSo urce = dv;

I hope this helps. In case of any difficult feel free to get back.

--
Regards,
Tushar
MCTS - .NET 2.0 Web App
"Gerhard" wrote:
I have a vb.net 2.0 app that is loading a GridView with a DataSource that is
returned from a function.

The definitions in the function are:

Dim ReportDS As DataSet = New DataSet
Dim ReportTable As System.Data.Dat aTable = New
System.Data.Dat aTable("SendTo" )

The ReportTable is populated row by row by data gotten back from the
Exchange server.

I then set ReportDS.Tables .Add(ReportTabl e) and return ReportDS

I then set GridView.DataSo urce = ReportDS()

This displays exactly as I want it to.

The question is how do I enable sorting on the GridView where it will
actually sort? Setting AllowSorting="T rue" causes a post back, but no
sorting occurs. What is the optimal way to be able to enable sorting here?

Thanks.

Apr 15 '07 #3
Hi Gerhard,

For the further question about the "Date" column, it is caused by the way
you create the "Date" column(as below):

ReportTable.Col umns.Add("Date" )

The above method will always create a new column in DataTable and set its
datatype to "String". That's why you found that the values in the "Date"
column are sorted as string values. To make them work as DateTime instance,
you need to specify the datatype(as DateTime) when creating the column. e.g.

===============
Dim ReportTable As New DataTable

'specify the type of the column as DateTime

ReportTable.Col umns.Add("Date" , GetType(DateTim e))
===============

Hope this helps.
Sincerely,

Steven Cheng

Microsoft MSDN Online Support Lead
This posting is provided "AS IS" with no warranties, and confers no rights.

Apr 16 '07 #4
Thank you :)

"Steven Cheng[MSFT]" wrote:
Hi Gerhard,

For the further question about the "Date" column, it is caused by the way
you create the "Date" column(as below):

ReportTable.Col umns.Add("Date" )

The above method will always create a new column in DataTable and set its
datatype to "String". That's why you found that the values in the "Date"
column are sorted as string values. To make them work as DateTime instance,
you need to specify the datatype(as DateTime) when creating the column. e.g.

===============
Dim ReportTable As New DataTable

'specify the type of the column as DateTime

ReportTable.Col umns.Add("Date" , GetType(DateTim e))
===============

Hope this helps.
Sincerely,

Steven Cheng

Microsoft MSDN Online Support Lead
This posting is provided "AS IS" with no warranties, and confers no rights.

Apr 17 '07 #5

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

Similar topics

0
2719
by: ck388 | last post by:
For some reason when I enable the callback feature of the gridview I still get a page refresh, that is it seems like there is a postback that occurs, not a callback which is just supposed to update not the whole page, but a portion of the page. Strangely enough the URL below ...
2
11105
by: Arjen | last post by:
Hi, I get this error message when sorting a gridview: The GridView 'GridView1' fired event Sorting which wasn't handled What do I need to do? Thanks!
4
8237
by: samb | last post by:
When I use manual databinding to a GridView control, as bellow. 'Retrive a DataSet from database Dim ds As DataSet = uda.GetUsers(conectionString) 'gvUsers - The GridView gvUsers.DataSource = ds gvUsers.DataBind()
4
5469
by: kurt sune | last post by:
I have a an aspx page with a gridview. The gridview is data bound to a generic list of custom classes. The gridview's DataSource is thus not set. Now I want to add sorting to it. So I create an eventhandler thus: Protected Sub grdResult_Sorting(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewSortEventArgs) Handles...
0
1756
by: jobo | last post by:
Hey there, I'm having a problem getting sorting to work. Here's what the GridView looks like: "server" ID="updt1" Mode="Conditional">
2
5574
by: sivagururaja | last post by:
Hi All, How can i sorting the Gridview Columns via the code behind. When i tried to sorting the column it doesn't work. SqlConnection con = new SqlConnection("Connection string"); con.Open(); SqlCommand cmd = new SqlCommand(str, con); SqlDataAdapter da = new SqlDataAdapter(cmd);
3
22747
by: =?Utf-8?B?YmJkb2J1ZGR5?= | last post by:
I have a question that maybe somebody can help me out. I have a gridview that is bound to a sqltable, and I have created two template columns. I am having problems getting the sorting to work. I turned on the Allow Sorting property but when I click one of the columns that is bound, it will not sort. Below is the code I am using
3
1926
by: Nathan Sokalski | last post by:
I have a GridView control with three columns, all BoundField columns. They all have a HeaderText and DataField property set, and the third one has a DataFormatString property as well. When I run my code, the GridView displays two sets of columns. The first set looks exactly as I would expect. The second set, which should not be there anyway,...
0
1523
by: Sobin Thomas | last post by:
Hi All, How can I bind the Gridview control to Sql Datasource control on a button click(I see majority of the articles binding datasource at page load) I need to enable the paging and sorting of the Gridview control also .Actually I am able to bind the sql datasource control to the Gridview on button Click but on clicking the GridView for...
0
7695
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
7612
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
7922
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
0
8119
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
0
7964
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
0
6281
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
0
3653
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
1
1209
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
936
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

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.