ASP.NET动态数据网站:力第一列中按字母顺序排列 [英] ASP.NET Dynamic Data Site: Force First Column to be Alphabetized
问题描述
我已经部署了ASP.NET动态数据网站在这里: https://ess.orthman.com/PhoneListWeb /
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?
推荐答案
您有许多可供选择,这取决于你想要订购的负担的设备。
You have a number of options available, depending on which machine you want the burden of ordering.
1 您可以将DB服务器这将 SELECT * FROM ... ORDER BY ...
和使用上创建一个存储过程在你的.dbml
1. You can create a Stored Procedure on the DB server which will SELECT * FROM ... ORDER BY ...
and use that in your .dbml
2 您提到您正在使用LINQ到从的.dbml生成的SQL类,所以我要对你所使用的假设的LinqDataSource
在.aspx页面。
2. 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.
从你的设计师中,您可以在选择配置数据源的的LinqDataSource
:
From within your designer, you can select Configure Data Source on your LinqDataSource
:
然后你从你的.dbml选择你的背景,并在下一个屏幕上,你必须订购选项通过:
Then you choose your Context from your .dbml, and on the next screen you have the option to Order By:
3。使用动态数据网站你不有一个特定的表结构的优点在设计时间。正因为如此,你需要创建一个排序,将在运行时发生。您可以编辑你的 DynamicData \\ PageTemplates \\ List.aspx.cs
来包括以下内容:
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:
protected void Page_Load(object sender, EventArgs e)
{
Title = table.DisplayName;
// Disable various options if the table is readonly
if (table.IsReadOnly)
{
GridView1.Columns[0].Visible = false;
InsertHyperLink.Visible = false;
GridView1.EnablePersistedSelection = false;
}
// Add our sort to the first data column.
if (!Page.IsPostBack)
{
GridView1.Sort(table.Columns[0].Name, SortDirection.Ascending);
}
}
这篇关于ASP.NET动态数据网站:力第一列中按字母顺序排列的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!