I have deployed a ASP.NET Dynamic Data Site here: https://ess.orthman.com/PhoneListWeb/
The Columns can be alphabetized by clicking on the Column name, but how can I set the site to automatically alphabetize that first column?
I have deployed a ASP.NET Dynamic Data Site here: https://ess.orthman.com/PhoneListWeb/
The Columns can be alphabetized by clicking on the Column name, but how can I set the site to automatically alphabetize that first column?
After Binding the Data From dbml You might have a linq statement to bind Data into a Grid or List.
Code something similar to the Same.
In this Below sample code, I have just added sorting on binding the data
Order by COMPANY NAME ASCENDING
Order by COMPANY NAME DESCENDING
Try this Hope it will help
If you are using
ASP.NET 4.0
you can consider GridView'sAllowSorting = true
with new sorting-related style propertiesSortedAscendingHeaderStyle
and other.Example of
.ASPX
:Example of
.CSS
:AllowSorting
prompts the GridView to render its header row usingLinkButton
controls that, when clicked, cause a postback and initiate the sorting process. And new properties allow to define the visual appearance of the column header depending on current order.More information you can find at MSDN.
EDIT:
If you would like to sort only by the first column, you should set
SortExpression
property ofDynamicField
control of the other columns to blank.First and simple answer will be sorting your data sources
Using order by before fetching data (form DB) or linq sort objects after fetching them ...
You can use the DisplayColumnAttribute to designate the column that should be used for sorting. There is a simple and easy way to sort and there is a more complex and powerful approach. I will give you both.
The simple way first, showing an example of how to sort an entity. In this example the PostalCode column from the Address table (the parent table) is used for sorting the Address.
If your sorting needs are more complex then try this more robust approach from the C# Bits blog: Setting the initial sort order
This link documents the DisplayColumnAttribute.
You have a number of options available, depending on which machine you want the burden of ordering.
1. You can create a Stored Procedure on the DB server which will
SELECT * FROM ... ORDER BY ...
and use that in your .dbml2. You mentioned you are using Linq to SQL classes generated from a .dbml, so I am going on the assumption you are using
LinqDataSource
in your .aspx pages.From within your designer, you can select Configure Data Source on your
LinqDataSource
:Then you choose your Context from your .dbml, and on the next screen you have the option to Order By:
3. Using Dynamic Data Web Site you do not have the advantage of a specific table structure at design time. Because of this, you need to create a sort that will happen at runtime. You can edit your
DynamicData\PageTemplates\List.aspx.cs
to include the following: