Last post Nov 26, 2010 04:20 PM by sjnaughton
Nov 24, 2010 06:25 AM|micmac|LINK
I have a visual basic website in VS 2010 framework 4, linx to SQL, with scafolding.... and this dataclass has about 10 foreign key fields, of which all 10 are shown in the list view of the website. I want the ability to exclude those filters from the list
view (or exclude some and keep some), but without eliminating them from the edit forms. Using <scafoldingcolumn("False")> does the trick to remove them entirely but that will also remove them from the grid/list itself, which I don't want, and remove the column
from the edit record views, which I don't want either.
Any help would be great!!!!
Nov 24, 2010 07:32 AM|sjnaughton|LINK
Hi Micmac, I have a sample here A New Way To Do Column Generation in Dynamic Data 4 that implements my old sample Dynamic
Data - Hiding Columns in selected PageTemplates for .Net 4, this allows you to choose wich page columns appear in.
(it's c# sorry [:(])
Dynamic Data 4
Nov 24, 2010 07:43 AM|micmac|LINK
Thanks so much for the quick reply! Yes I have come across this posting in my search prior to submitting the question but am having some trouble converting from C to VB... but I can stumble through that. The question is, where do I implement the code???
Within a new class?
Nov 24, 2010 08:46 AM|sjnaughton|LINK
You create a set of classes that inherit from the MetaModle and MetaTable classes. These can be in a seperate class library or in classes in the project or webiste (App_Code folder).
Nov 24, 2010 11:50 AM|olegsych|LINK
Use [Display(AutoGenerateFilter=false)] attribute for foreign key columns that you don't want to display the drop-down list filters.
Nov 24, 2010 12:18 PM|micmac|LINK
THAT WAS IT! I have the Display function applied to all the fields to set my order already and didn't think to try the AutoGenerateFilter command! Worked like a charm. The prior, more intricate solution will be great to try for when I want those filter
to display on certain pages, thank you, but for this short term need to just excude from list view this worked like a CHARM! 5 days of digging... upwards of 20 hours of trial/error/try again... And yet again that feeling of ... AWESOME IT's FIGURED OUT...
followed by "How Stupid that I didn't figure this our eariler".
Nov 26, 2010 08:27 AM|micmac|LINK
Now a part 2 to this question... what's the easiest way to sort the values in the foreign key dropdowns acending? I have seen some C+ code which Steve has written but I can't seem to figure out the translation to VB?
Nov 26, 2010 08:36 AM|sjnaughton|LINK
On the Tables class in your metadata you add the DisplayColumn attribute like so:
[DisplayColumn("DisplayColumn", "SortColumn", true)]
the first parameter is the column to display, the second is the column to sort on (if you want to sort you must supply this second value) and the third is optional, set it to true if you want to sort descending.
Nov 26, 2010 09:17 AM|micmac|LINK
Thanks Steve. So I assume, correct me if I am wrong, that you wrote the C equivilent of the VB which should read :
Where owner is the field I want to be displayed and sorted on.
But I receive the following error?
BC30662: Attribute 'DisplayColumnAttribute' cannot be applied to 'Owner' because the attribute is not valid on this declaration type.
Nov 26, 2010 09:22 AM|sjnaughton|LINK
Hi Micmac, That is the correct way to apply it I'll test it here on a VB project.
Nov 26, 2010 09:26 AM|sjnaughton|LINK
Hi Micmac, here's my workign class on Employee for Northwind:
<DisplayColumn("LastName", "LastName", True)> _
Partial Public Class [Employee]
Public Overrides Function ToString() As String
Return Me.FirstName + ", " + Me.LastName
Public Class [EmployeeMD]
Public EmployeeID As Object
Public LastName As Object
Public FirstName As Object
Public Title As Object
Public TitleOfCourtesy As Object
Public BirthDate As Object
Public HireDate As Object
Public Address As Object
Public City As Object
Public Region As Object
Public PostalCode As Object
Public Country As Object
Private newHomePhone As Object
<DisplayName("Home Phone")> _
Public Property HomePhone() As Object
Set(ByVal value As Object)
newHomePhone = value()
Public Extension As Object
Public Photo As Object
Public Notes As Object
Public ReportsTo As Object
Public PhotoPath As Object
Public Employees As Object
Public EmployeeTerritories As Object
Public Orders As Object
Public Employee As Object
As you can see the attribute is not applied to the metadata/buddy class the but the partial class, however it should work the other way also.
Also note with VB for some properties you MUST declare a property not a field.
Nov 26, 2010 10:02 AM|micmac|LINK
Sorry you have to deal with such "beginner" here, as I am. The issue was that my field type in SQL was a "text" type, and the error was a product the error was a product of the inability to sort a text field! I converted the field type to nvarchar() and
it worked perfect with the code you provided. Thank you
Nov 26, 2010 04:20 PM|sjnaughton|LINK
Great new Micmac [:)]