first of all because you are referring to DynamicGridView it's probably the case that you are using the December '07 CTP. That version is quite outdated at this point and I would invite you to download either the
.NET Framework 3.5 SP1 or the cutting edge version of
Dynamic Data on Code Gallery.
I know that this is an older posting. Has this been added yet? I really desparately need this functionality.
I have seen posts about work arounds, but am too much of a noobie to have a clue what they are talking about. I am just now learning VB, so people throwing code at me and saying "add it" doesn't help me much. I really need to know more specifics, like
WHERE to add it.
If anyone has any suggestions or help they can provide, I sure would appreciate it.
I have tried this "DisplayColumnAttribute.SortColumn" and the link doesn't work...so tried searching for it, but doesn't
seem to be for the Filters...at least not from what I am understanding.
Have a look at this I think it may be what you need:
[MetadataType(typeof(EmployeeMD))]
[DisplayColumn("LastName","LastName",false)]
public partial class Employee
{
public class EmployeeMD
{
public object EmployeeID { get; set; }
[UIHint("MultilineText")]
public object LastName { get; set; }
public object Title { get; set; }
public object TitleOfCourtesy { get; set; }
//... more fields here
}
}
the DisplayColumn takes 3 parameters
Is the column to display
Is the column to sort on
Is set to true for dort descending
This affects the Filters and the ForeignKey_Edit filedTemplates.
Hope this helps [:D]
Dynamic DatafiltersSorting
See my blog C# Bits | Twitter @sjnaughton Always seeking an elegant solution.
Again...WHERE does it go? I have no idea which file this would need to go in. I already have this information, but have tried to figure out where to put it and cannot determine it.
Do you put it into the ForeignKey_Edit Template? Do you put it in the Custom Template for the Table you want to use it on? Do you put it in the Default page? What about the pages that handle ALL of the Tables...does it go in that file?
Also, is 'EmployeeMD' the table name or is 'Employee' the table name? Whichever is not the table name...what is it? A column in the table? Or a new name?
I kind of get the feeling that the 'EmployeeMD' is the table and that the 'public objects' are the columns... Is that right?
You create a partial class file (in the App_Code folder in a file based website) along with the Linq to SQL files. You create a class with the partial class that represent the entity in the Linq to SQL classes (Look in the <ModelName>.designer.cs file for
the class names etc) and then add the metadata, also see these videos here:
http://www.asp.net/learn/3.5-SP1/ in the ASP.NET Dynamic Data section.
Hope this helps [:D]
Dynamic DataMetadataPartial Classes
See my blog C# Bits | Twitter @sjnaughton Always seeking an elegant solution.
Marked as answer by ricka6 on Nov 26, 2008 04:50 PM
Okay, I have done what I think you said to do, but am getting errors.
I created a new class file in the App_Code folder called "Series_Master_Best_Cost", which is the name of my table, and it is how the class is declared in the 'designer.vb' file in the App_Code folder.
I changed the parameters in 'DisplayColumn' to "User_Master", which is the column name for the Filter that I need sorted in alphabetical order.
It is complaining about 'DisplayColumn', saying "Declaration Expected". I made a declaration, but still didn't seem to like it.
I had to comment out 'Option Strict On' because it kept complaining about the parameters for 'DisplayColumn', but that still did not fix things.
Here is the error information I am getting:
Input string was not in a correct format.
Description:
An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
Exception Details: System.FormatException: Input string was not in a correct format.
Source Error:
Line 6: <MetadataType(GetType(Series_Master_Best_Cost))> _ Line 7: Partial Public Class [Series_Master_Best_Cost] Line 8: Dim DisplayColumn("USER_MASTER", "USER_MASTER", False) Line 9: Public Class [Series_Master_Best_Cost] Line 10:
Got the error to go away. Found some information on http://msdn.microsoft.com/en-us/library/cc679189.aspx that showed a little different information, but still is not sorting my column. I am guessing it is now a matter of me not having the right information
in each of the parameters, classes, or types.
<MetadataType(GetType(Series_Master_Best_Cost))> _
Partial Public Class Series_Master_Best_Cost
<DisplayColumn("USER_MASTER", "USER_MASTER", False)> _
Public Class Series_Master_Best_Cost
End Class
End Class
Is there something else that I am missing?
I also tried 'Series_Master_Best_CostMD' in the MetadataType and Public Class (not Partial), which seemed to follow what others had done, but then it said that the type was not defined.
What is the difference between DisplayColumnAttribute and DisplayColumn...they seem to both be used in that page referenced above.
Has anyone else been able to get this to work? I have changed it as suggested (and closed the second class too), and it still does not sort the filtered list...or anything else for that matter...
There must be something other than this that I am not getting done.
While I am a novice, it seems to me that this is trying to sort the COLUMN "user_master", not the filtered dropdown list, but that isn't sorted either...
This wouldn't be such a big issue, but we have thousands of employees in our company and trying to find one of them in an unsorted list is not possible!
Maybe an example will help; let's assume that your model generates the folowing classes (sorry for using C# syntax):
public partial class Product {
public Category MyCategory;
}
public partial class Category {
public string Name;
public int Code;
}
Now say you are displaying your Products list. Since Product has a foreign key reference to Category, a filter in the form of a drop-down will be generated for the MyCategory column. I am assuming now that you want to customize the order in which the items appear in this dropdown. If you are trying to do something different, please clarify.
So to customize this ordering, you would decorate the Category class (since this is the type of the MyCategory property on Product) with DisplayColumnAttribute, initialized as follows:
[DisplayColumnAttribute("Name", "Code", true)]
public partial class Category {
}
This will cause Dynamic Data to display the values in the dropdown using the value of the Name property, but they will be ordered in descending order based on the Code property.
As was noted earlier, you would add it in code to your App_Code folder (if in a WebSite project) or just as a class anywhere inside of a Web Application project. Since this is a class-level attribute, you don't need to use MetadataTypeAttribute.
You asked about the difference between [DisplayColumnAttribute] and [DisplayColumn]. There is none. The compiler automatically infers that if you have [DisplayColumn] you actually mean [DisplayColumnAttribute]. Note that this behavior only applies to attributes
when they are used to decorate code (and not ones instantiated in code).
marcind
Contributor
3344 Points
609 Posts
Microsoft
Re: Dynamic filter order by
May 23, 2008 03:27 PM|LINK
Hi Case,
first of all because you are referring to DynamicGridView it's probably the case that you are using the December '07 CTP. That version is quite outdated at this point and I would invite you to download either the .NET Framework 3.5 SP1 or the cutting edge version of Dynamic Data on Code Gallery.
Once you have the recent bits, you can use DisplayColumnAttribute.SortColumn to provide sorting information.
ASP.NET Team
@marcind
Blog
tigra68
Member
42 Points
24 Posts
Re: Dynamic filter order by
Nov 26, 2008 12:15 PM|LINK
I know that this is an older posting. Has this been added yet? I really desparately need this functionality.
I have seen posts about work arounds, but am too much of a noobie to have a clue what they are talking about. I am just now learning VB, so people throwing code at me and saying "add it" doesn't help me much. I really need to know more specifics, like WHERE to add it.
If anyone has any suggestions or help they can provide, I sure would appreciate it.
I have tried this "DisplayColumnAttribute.SortColumn" and the link doesn't work...so tried searching for it, but doesn't seem to be for the Filters...at least not from what I am understanding.
Thanks, Ann
sjnaughton
All-Star
27330 Points
5459 Posts
MVP
Re: Dynamic filter order by
Nov 26, 2008 12:56 PM|LINK
Have a look at this I think it may be what you need:
[MetadataType(typeof(EmployeeMD))] [DisplayColumn("LastName","LastName",false)] public partial class Employee { public class EmployeeMD { public object EmployeeID { get; set; } [UIHint("MultilineText")] public object LastName { get; set; } public object Title { get; set; } public object TitleOfCourtesy { get; set; }//... more fields here } }
the DisplayColumn takes 3 parameters
This affects the Filters and the ForeignKey_Edit filedTemplates.
Hope this helps [:D]
Dynamic Data filters Sorting
Always seeking an elegant solution.
tigra68
Member
42 Points
24 Posts
Re: Dynamic filter order by
Nov 26, 2008 01:10 PM|LINK
Again...WHERE does it go? I have no idea which file this would need to go in. I already have this information, but have tried to figure out where to put it and cannot determine it.
Do you put it into the ForeignKey_Edit Template? Do you put it in the Custom Template for the Table you want to use it on? Do you put it in the Default page? What about the pages that handle ALL of the Tables...does it go in that file?
Also, is 'EmployeeMD' the table name or is 'Employee' the table name? Whichever is not the table name...what is it? A column in the table? Or a new name?
I kind of get the feeling that the 'EmployeeMD' is the table and that the 'public objects' are the columns... Is that right?
Thanks, Ann
sjnaughton
All-Star
27330 Points
5459 Posts
MVP
Re: Dynamic filter order by
Nov 26, 2008 01:20 PM|LINK
You create a partial class file (in the App_Code folder in a file based website) along with the Linq to SQL files. You create a class with the partial class that represent the entity in the Linq to SQL classes (Look in the <ModelName>.designer.cs file for the class names etc) and then add the metadata, also see these videos here: http://www.asp.net/learn/3.5-SP1/ in the ASP.NET Dynamic Data section.
Hope this helps [:D]
Dynamic Data Metadata Partial Classes
Always seeking an elegant solution.
tigra68
Member
42 Points
24 Posts
Re: Dynamic filter order by
Nov 26, 2008 02:05 PM|LINK
Okay, I have done what I think you said to do, but am getting errors.
I created a new class file in the App_Code folder called "Series_Master_Best_Cost", which is the name of my table, and it is how the class is declared in the 'designer.vb' file in the App_Code folder.
I changed the parameters in 'DisplayColumn' to "User_Master", which is the column name for the Filter that I need sorted in alphabetical order.
It is complaining about 'DisplayColumn', saying "Declaration Expected". I made a declaration, but still didn't seem to like it.
I had to comment out 'Option Strict On' because it kept complaining about the parameters for 'DisplayColumn', but that still did not fix things.
Here is the error information I am getting:
Input string was not in a correct format.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.Exception Details: System.FormatException: Input string was not in a correct format.
Source Error:
Source File: D:\Intranet\BestCost\App_Code\Series_Master_Best_Cost.vb Line: 8
tigra68
Member
42 Points
24 Posts
Re: Dynamic filter order by
Nov 26, 2008 02:31 PM|LINK
Got the error to go away. Found some information on http://msdn.microsoft.com/en-us/library/cc679189.aspx that showed a little different information, but still is not sorting my column. I am guessing it is now a matter of me not having the right information in each of the parameters, classes, or types.
This is my partial class file:
Imports Microsoft.VisualBasic
Imports System.Web.DynamicData
Imports System.ComponentModel
Imports System.ComponentModel.DataAnnotations
<MetadataType(GetType(Series_Master_Best_Cost))> _
Partial Public Class Series_Master_Best_Cost
<DisplayColumn("USER_MASTER", "USER_MASTER", False)> _
Public Class Series_Master_Best_Cost
End Class
End Class
Is there something else that I am missing?
I also tried 'Series_Master_Best_CostMD' in the MetadataType and Public Class (not Partial), which seemed to follow what others had done, but then it said that the type was not defined.
What is the difference between DisplayColumnAttribute and DisplayColumn...they seem to both be used in that page referenced above.
Anything else you can tell me?
Thanks, Ann
sjnaughton
All-Star
27330 Points
5459 Posts
MVP
Re: Dynamic filter order by
Nov 26, 2008 05:27 PM|LINK
Imports Microsoft.VisualBasic
Imports System.Web.DynamicData
Imports System.ComponentModel
Imports System.ComponentModel.DataAnnotations
<MetadataType(GetType(Series_Master_Best_Cost))> _
<DisplayColumn("USER_MASTER", "USER_MASTER", False)> _
Partial Public Class Series_Master_Best_Cost
Public Class Series_Master_Best_Cost
End Class
I think it should be more like this the table level attributes on the partial class.
Dynamic Data Metadata Partial Classes
Always seeking an elegant solution.
tigra68
Member
42 Points
24 Posts
Re: Dynamic filter order by
Nov 26, 2008 06:14 PM|LINK
Has anyone else been able to get this to work? I have changed it as suggested (and closed the second class too), and it still does not sort the filtered list...or anything else for that matter...
There must be something other than this that I am not getting done.
While I am a novice, it seems to me that this is trying to sort the COLUMN "user_master", not the filtered dropdown list, but that isn't sorted either...
This wouldn't be such a big issue, but we have thousands of employees in our company and trying to find one of them in an unsorted list is not possible!
Any help would be great!
HAPPY THANKSGIVING TO ALL!!!
Thanks, Ann
marcind
Contributor
3344 Points
609 Posts
Microsoft
Re: Dynamic filter order by
Nov 26, 2008 07:59 PM|LINK
Maybe an example will help; let's assume that your model generates the folowing classes (sorry for using C# syntax):
public partial class Product { public Category MyCategory; } public partial class Category { public string Name; public int Code; }Now say you are displaying your Products list. Since Product has a foreign key reference to Category, a filter in the form of a drop-down will be generated for the MyCategory column. I am assuming now that you want to customize the order in which the items appear in this dropdown. If you are trying to do something different, please clarify.
So to customize this ordering, you would decorate the Category class (since this is the type of the MyCategory property on Product) with DisplayColumnAttribute, initialized as follows:
This will cause Dynamic Data to display the values in the dropdown using the value of the Name property, but they will be ordered in descending order based on the Code property.
As was noted earlier, you would add it in code to your App_Code folder (if in a WebSite project) or just as a class anywhere inside of a Web Application project. Since this is a class-level attribute, you don't need to use MetadataTypeAttribute.
You asked about the difference between [DisplayColumnAttribute] and [DisplayColumn]. There is none. The compiler automatically infers that if you have [DisplayColumn] you actually mean [DisplayColumnAttribute]. Note that this behavior only applies to attributes when they are used to decorate code (and not ones instantiated in code).
ASP.NET Team
@marcind
Blog