473,398 Members | 2,120 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,398 software developers and data experts.

Sorting in gridview

I am getting a set of data from this webservice http://www.webservicex.net/stockquote.asmx?op=GetQuote. It returns a string. Following is my code.

Expand|Select|Wrap|Line Numbers
  1. stockQuote = stocks.GetQuote(txtStock.Text)
  2. quoteDoc.LoadXml(stockQuote)
  3. stockNode = quoteDoc.SelectSingleNode("StockQuotes/Stock")
  4.  
  5. grdStocks.DataSource = stockNode
  6. grdStocks.DataBind()
  7. grdStocks.Sort("StockFields",Sort.Ascending)
  8.  
  9. Protected Sub grdStocks_Sorting(......)
  10. grdStocks.DataSource = stockNode
  11. grdStocks.DataBind()
  12. End Sub
  13.  
  14. <asp:GridView ID="grdStocks" runat="server" >
  15.  <Columns>
  16. <asp:BoundField DataField="Name" HeaderText="StockFields" />
  17. <asp:BoundField DataField="InnerText" HeaderText="Value" />
  18. </Columns>
  19. </asp:GridView>
  20.  
However this code doesn't get fields sorted out. How I am suppose to sort it out?
Jul 20 '09 #1
1 3001
Frinavale
9,735 Expert Mod 8TB
Hey :)

Sorry I couldn't answer your question sooner but here it goes.

The GridView has a built-in sorting feature. First you have to enable the GridView to allow sorting by setting the AllowSorting property. Once you've done this the column headers will become hyperlinks and will the GridView to raise 2 events: the GridView Sorting and Sorted events.

So your GridView should look something like:
Expand|Select|Wrap|Line Numbers
  1. <asp:GridView ID="grdStocks" runat="server"  AllowSorting="true">
  2. <!-- ........  -->
  3. </asp:GridView>
  4.  
You'll have to handle GridView Sorting Event to provide custom sorting that should be done on the data.

The thing is that your GridView's DataSource is an XMLDocument (I think?).
XMLDocuments do not have built-in sorting functionality.

You're going to have to use XSL on the XML to sort it. I've never done this before and you'll probably be better off asking for help with regards to this in the XML forum.

Or you could use different control for the GridView's DataSource. Something that does have sorting capabilities...like the DataView.

-Frinny
Jul 21 '09 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

0
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...
2
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
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...
4
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...
0
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
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");...
4
by: =?Utf-8?B?R2VyaGFyZA==?= | last post by:
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...
3
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....
0
by: =?Utf-8?B?QVZM?= | last post by:
Hi, I've a requirement in which I want to use the custom sorting.. I mean I've a dropdown with sortable column names and when the user selects the particular column from dropdown , I need to sort...
1
by: dorandoran | last post by:
The sort on the childgrid is not working; nothing happens when I click on the each column header for sort. (I followed Satay's sample: http://www.codeproject.com/KB/aspnet/EditNestedGridView.aspx)...
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...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
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,...

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.