在 Asp.Net 动态数据应用程序中使用 DisplayColumnAttribute 按多个字段排序?
我有一个动态数据应用程序,我想根据多个字段进行排序,如下所示..
<DisplayColumn("FieldName", "Field1, Field2")> _
DisplayColumn 似乎不支持多个字段?
I've got a dynamic data app, and I want to sort based on multiple fields like so..
<DisplayColumn("FieldName", "Field1, Field2")> _
DisplayColumn doesn't seem to support more than one field?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
DisplayColumn 属性的 SortColumn 参数指定当该实体用作外键时(例如:在 DropDownList 中)而不是在 GridView 中排序(或在 DB 中排序)时用于对此实体进行排序的列。
也可以在这里看到:
ASP.NET 动态数据 DisplayColumn 属性导致排序问题
msdn: http://msdn.microsoft.com/ en-us/library/system.componentmodel.dataannotations.displaycolumnattribute.aspx
如果这仍然是您正在寻找的内容(仅在 DropDownLists 中排序,而不是在数据库中排序),您可以通过在中创建自定义属性来对多列进行排序组合这两列的实体。
例子:
The DisplayColumn attribute's SortColumn param specifies the column that will be used to sort this entity when it is used as a foreign key (ex: in a DropDownList), not when it is being sorted in the GridView (or being sorted in the DB).
see SO here as well:
ASP.NET Dynamic Data DisplayColumn Attribute Causing Sorting Issue
msdn: http://msdn.microsoft.com/en-us/library/system.componentmodel.dataannotations.displaycolumnattribute.aspx
If this is still what you are looking for (sorting in DropDownLists only, not the DB) you can sort on multiple columns by creating a custom property in the entity that combines those two columns.
example:
如果您想对多列上的 gridview 进行排序,那么您可以这样做 -
在 Page Template\List.aspx.cs & 中在 Page_Laod 事件中检查表名
if (!Page.IsPostBack)
{
if (表.Name == "项目")
{
GridView1.Sort("ClientDetail.CompanyName asc,ProjectName asc", SortDirection.Ascending);
您
还可以为每列提供升序或降序的顺序。
If you want to sort gridview on multiple columns then this is how you can do -
In Page Template\List.aspx.cs & in Page_Laod event check for table name
if (!Page.IsPostBack)
{
if (table.Name == "Project")
{
GridView1.Sort("ClientDetail.CompanyName asc,ProjectName asc", SortDirection.Ascending);
}
and you can also provide order either ascending or descending for each column.
是的,它确实支持多个字段。您可以尝试以下操作:
然后在
List.aspx
的Page_Load
中:Yes it does support multiple field. You can try this:
Then in
Page_Load
ofList.aspx
: