473,385 Members | 1,983 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,385 software developers and data experts.

GridView Sorting Problem

7
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 2312
jhardman
3,406 Expert 2GB
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
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...
5
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...
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">
12
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...
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...
2
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 ...
0
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...
1
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...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
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: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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...

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.