动态数据中的字段顺序?
有谁知道是否可以在动态数据中选择字段的顺序(当然,无需自定义每个表的模板)?
谢谢 !
Does anybody know if it is possible to choose the order of the fields in Dynamic Data (of course, without customizing the templates of each table) ?
Thanks !
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(7)
在.NET 4.0中,使用4.0版本的动态数据dll,您可以像这样设置数据注释:
In .NET 4.0, using the 4.0 release of the Dynamic Data dll, you can set data annotations like so:
根据 this 线程 - 您可以在动态数据 futures dll 中使用 ColumnOrderAttribute 。 您可以从 Codeplex 获取期货。
As per this thread - you can use the ColumnOrderAttribute in the dynamic data futures dll. You can grab the futures from codeplex.
您可以通过修改 LINQ to SQL 文件中公共属性的顺序来完成此操作。
例如,我进入 Northwind.designer.cs(这是我自动生成的 LINQ to SQL 文件),并将名为 Products 的公共属性移至公共分部类 Category 中的公共属性 CategoryName 之上。 然后我重新编译,默认模板以我的新顺序显示列。
当然,这意味着您编辑自动生成的代码,如果重新生成它,您的更改就会丢失,因此这种技术并非没有危险。
You can do this by modifying the order of the public properties in your LINQ to SQL file.
For example, I went into Northwind.designer.cs which was my auto-generated LINQ to SQL file and moved the public property named Products above the public property CategoryName in the public partial class Category. Then I recompiled and the default template displayed the columns in my new order.
Of course, this means your editing auto-generated code and if you regenerate it, your changes are lost, so this technique is not without peril.
您必须在 DynamicData 文件夹中创建自定义页面。
步骤如下:
以下是 ScottHa 的截屏视频:
http://www.asp.net/learn/3.5-SP1/ video-293.aspx
You have to create a custom page in DynamicData folder.
Here are the steps:
Here is a screencast from ScottHa:
http://www.asp.net/learn/3.5-SP1/video-293.aspx
GridView 具有 ColumnsGenerator 属性,通过实现 IAutoFieldGenerator 接口的GenerateFields 方法来使用它,您可以在其中根据自定义规则(属性、元信息等)设置字段顺序
GridView have ColumnsGenerator property, use it by implementing GenerateFields method of IAutoFieldGenerator interface in which you can set fields orders based on your custom rules (attributes, meta info, ...)
为了避免使用动态数据 futures dll,您可以按如下方式滚动自己的 ColumnOrder 属性:
然后在实现 IAutoFieldGenerator 的类中,您
最终的用法如下
To avoid using the Dynamic Data futures dll, you can roll your own ColumnOrder attribute as follows:
and then in your class that implements IAutoFieldGenerator, you have
and finally your usage would look like
我正在回答一个老问题,因为在我看来,可能的解决方案在新版本的框架中发生了变化。
看来 Display(Order) 现在可以直接按照要求工作(.NET 4.0 上的 Visual Web Developer 2010),无需任何特定的解决方法。
示例:
一件重要的事情是检查正确的对象名称以映射外键:
在一个项目中,实体类中的字段 OperatoreID 被翻译为:
作为 Operatore 外键的源表; 对于同一张表上的第二个引用,它将得到类似 1 的值,依此类推。
I'm answering an old question because it seems to me that the possible solution changed in newer versions of the framework.
It seems that the Display(Order) works now directly as asked (Visual Web Developer 2010 on .NET 4.0) without any particular workaround.
Example:
An important thing it's to check the correct object name to map the foreignkey:
in one project a field OperatoreID translated in the entity class as:
being Operatore the source table of the foreignkey; for a second reference on the same table it will get something like 1 and so on.