Question

I have a ASP.NET dynamic data site that has multiple filter controls built using metadata such as:

[ScaffoldTable(true), MetadataType(typeof(Fees.Metadata))]
public partial class Fees
{
    public class Metadata
    {
        [FilterUIHint("DateRange")]
        public object InvoiceDate;
    }
{

How do I order these filters in a particular way. It seems very random. Can I use a metadata attribute or should I modify the page template, what's the go?

Was it helpful?

Solution

OK so I ended up just manually reordering the controls list on the custom code-behind page like so:

Control date_filter = FilterRepeater.Controls[1];
FilterRepeater.Controls.RemoveAt(1);
FilterRepeater.Controls.Add(date_filter); 

Of 3 controls on the page this takes the 2nd out and adds it onto the end.

If I need to use again I might create a method and search on control name.

This is a crude solution but it suits me for this one off scenario. If anyone finds a better way let me know.


OK better way:

  1. Install this: http://nuget.org/packages/NotAClue.DynamicData.Extensions
  2. Add reference "using NotAClue.ComponentModel.DataAnnotations;" if you are using a separate entity page
  3. Add [Filter(Order=1)] metadata tags to attributes

OTHER TIPS

In the end it was quite simple. I have four filters and now they come up in the right order.... All you need to do is to add in a Display/Order directive into the class metadata definition, like: where 'n' is the order of appearance.

In the Metadata definition I am using (VB - so you need to convert it to your scenario)..

My file name: OpCoProductRev.vb

<MetadataType(GetType(OpCoProductRevMetadata))>
Partial Public Class OpCoProductRev

End Class


Partial Public Class OpCoProductRevMetadata

    <Required()>
    <DisplayName("xxxx")>
    <UIHint("xxxx")>
    <FilterUIHint("xxxxFilter")>
    <Display(Order:=1)>
    Public Property xxxx As Object

    <Required()>
    <DisplayName("yyyyy")>
    <UIHint("yyyyy")>
    <FilterUIHint("yyyyyFilter")>
    <Display(Order:=2)>
    Public Property yyyyy As Object

    <Required()>
    <DisplayName("zzzzzz")>
    <UIHint("zzzzzz")>
    <FilterUIHint("zzzzzzFilter")>
    <Display(Order:=3)>
    Public Property zzzzzz As Object

    <Required()>
    <DisplayName("aaa")>
    <UIHint("aaa")>
    <FilterUIHint("aaaFilter")>
    <Display(Order:=4)>
    Public Property aaa As Object


End Class

Hope it helps...

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top