Cry*_*nes 1 c# asp.net asp.net-dynamic-data
我在这里部署了一个ASP.NET动态数据站点:https://ess.orthman.com/PhoneListWeb/
可以通过单击列名称对列进行按字母顺序排列,但如何将站点设置为自动按字母顺序排列第一列?
您有多种选择,具体取决于您希望订购的机器.
1.您可以在DB服务器上创建一个存储过程,SELECT * FROM ... ORDER BY ...并在.dbml中使用它
2.您提到您正在使用从.dbml生成的Linq到SQL类,因此我假设您LinqDataSource在.aspx页面中使用.
在设计器中,您可以选择配置数据源LinqDataSource:

然后从.dbml中选择Context,在下一个屏幕上,您可以选择Order By:

3.使用动态数据网站,您在设计时没有特定表结构的优势.因此,您需要创建一个将在运行时发生的排序.您可以编辑自己DynamicData\PageTemplates\List.aspx.cs以包含以下内容:
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);
}
}
Run Code Online (Sandbox Code Playgroud)