473,790 Members | 2,805 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

GridView Sorting Problem

7 New Member
I used this example straight from msdn in a gridview that already sorts based on each column. For some reason I cannot get it to sort based on two sorting expressions.Is there some property of the grid view i have to set in order for this to work?

Expand|Select|Wrap|Line Numbers
  1. <%@ Page language="C#" %>
  2.  
  3. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
  4.     "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  5. <script runat="server">
  6.  
  7.   void SortButton_Click(Object sender, EventArgs e)
  8.   {
  9.  
  10.     String expression = "";
  11.     SortDirection direction;
  12.  
  13.     // Create the sort expression from the values selected 
  14.     // by the user from the DropDownList controls. Multiple
  15.     // columns can be sorted by creating a sort expression
  16.     // that contains a comma-separated list of field names.
  17.     expression = SortList1.SelectedValue + "," + SortList2.SelectedValue;
  18.  
  19.     //  Determine the sort direction. The sort direction
  20.     // applies only to the second column sorted.
  21.     switch (DirectionList.SelectedValue)
  22.     {
  23.       case "Ascending":
  24.         direction = SortDirection.Ascending;
  25.         break;
  26.       case "Descending":
  27.         direction = SortDirection.Descending;
  28.         break;
  29.       default:
  30.         direction = SortDirection.Ascending;
  31.         break;
  32.     }
  33.  
  34.     // Use the Sort method to programmatically sort the GridView
  35.     // control using the sort expression and direction.
  36.     CustomersGridView.Sort(expression, direction);
  37.  
  38.   }
  39.  
  40. </script>
  41.  
  42. <html  >
  43.   <head runat="server">
  44.     <title>GridView Sort Example</title>
  45. </head>
  46. <body>
  47.     <form id="form1" runat="server">
  48.  
  49.       <h3>GridView Sort Example</h3>
  50.  
  51.       <table>
  52.         <tr>
  53.           <td>
  54.              Sort by:
  55.             <asp:dropdownlist ID="SortList1"
  56.               runat="server">
  57.               <asp:listitem Selected="true">CustomerID</asp:listitem>
  58.               <asp:listitem>CompanyName</asp:listitem>
  59.               <asp:listitem>Address</asp:listitem>
  60.               <asp:listitem>City</asp:listitem>
  61.               <asp:listitem>PostalCode</asp:listitem>
  62.               <asp:listitem>Country</asp:listitem>
  63.             </asp:dropdownlist>
  64.           </td>
  65.           <td colspan="2">
  66.             &nbsp;
  67.           </td>
  68.         </tr>
  69.         <tr>
  70.           <td>
  71.             Then by:
  72.               <asp:dropdownlist ID="SortList2"
  73.                 runat="server">
  74.                 <asp:listitem Selected="true">CustomerID</asp:listitem>
  75.                 <asp:listitem>CompanyName</asp:listitem>
  76.                 <asp:listitem>Address</asp:listitem>
  77.                 <asp:listitem>City</asp:listitem>
  78.                 <asp:listitem>PostalCode</asp:listitem>
  79.                 <asp:listitem>Country</asp:listitem>
  80.               </asp:dropdownlist>
  81.           </td>
  82.           <td>
  83.              Sort order:      
  84.           </td>
  85.           <td>
  86.             <asp:radiobuttonlist id="DirectionList"
  87.               runat="server">
  88.               <asp:listitem selected="true">Ascending</asp:listitem>
  89.               <asp:listitem>Descending</asp:listitem>
  90.             </asp:radiobuttonlist>
  91.           </td>
  92.         </tr>
  93.       </table>
  94.  
  95.       <asp:button id="SortButton"
  96.         text="Sort"
  97.         onclick="SortButton_Click" 
  98.         runat="Server"/>  
  99.  
  100.       <br/>
  101.       <hr/>
  102.       <br/>
  103.  
  104.       <asp:gridview id="CustomersGridView" 
  105.         datasourceid="CustomersSource" 
  106.         autogeneratecolumns="true"
  107.         emptydatatext="No data available." 
  108.         allowpaging="true" 
  109.         runat="server">
  110.       </asp:gridview>
  111.  
  112.       <!-- This example uses Microsoft SQL Server and connects  -->
  113.       <!-- to the Northwind sample database. Use an ASP.NET     -->
  114.       <!-- expression to retrieve the connection string value   -->
  115.       <!-- from the Web.config file.                            -->
  116.       <asp:sqldatasource id="CustomersSource"
  117.         selectcommand="Select [CustomerID], [CompanyName], [Address], [City], [PostalCode], [Country] From [Customers]"
  118.         connectionstring="<%$ ConnectionStrings:NorthWindConnectionString%>" 
  119.         runat="server"/>
  120.  
  121.     </form>
  122.   </body>
  123. </html>
Jul 27 '07 #1
1 2340
jhardman
3,406 Recognized Expert Specialist
moved to .NET forum. There is no such thing as a gridView in ASP classic.

Jared, moderator
ASP forum
Jul 30 '07 #2

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

Similar topics

0
2736
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 http://beta.asp.net/QUICKSTARTV20/aspnet/doc/ctrlref/data/gridview.aspx (VB GridView Paging and Sorting Callbacks example)
5
3377
by: yefei | last post by:
In my web design, I display records from a SQL DataBase according to some filters the GridView is defined with select commands and selest parameters however, I also want to display all records in the database when the user press a "View All" button. In this case, I need to change the select comand and clear the parameters. And I did this in the button_click() event. the GridView can display desired results when I press the "View All"...
4
8252
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
5481
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 grdResult.Sorting
0
1769
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">
12
3816
by: Cindy Lee | last post by:
When I do a sorta on 1 table, then the other table goes back to the original order. What can I set so, it keeps the order of the other current gridview's order. I set all the gridview values in my 'onpageload' in the cs file.
4
11163
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 ReportTable As System.Data.DataTable = New System.Data.DataTable("SendTo") The ReportTable is populated row by row by data gotten back from the
2
1385
by: mahesh123 | last post by:
Hi, I am using gridview in my form and binded the gridview with object datasource.I am trying to implement sorting for my grid view and i am getting following error.i am using asp.net with VB Server Error in '/' Application. -------------------------------------------------------------------------------- The data source 'objdsDataSource' does not support sorting with IEnumerable data. Automatic sorting is only supported with...
0
1534
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 paging or sorting , the Gridview vanishes!! In short, I want to bind the GridView control to a...
1
2025
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 paging or sorting , the Gridview vanishes!! In short, I want to bind the GridView control to a...
0
9666
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 usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10413
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. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10200
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 captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
9986
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 choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9021
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 launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
5422
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 the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
4094
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3707
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2909
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 effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.