How to change the way filters and foreign key columns are displayed on the DynamicData site?

Well, my name doesn’t help. But read the message and you will understand.

What I want to do:

Suppose I have a Flyer table with 2 columns on my SQl server:

  • FlyerID (int) (PK)
  • FlyerDate (smalldatetime)

FlyerID is a foreign key for other tables, for example Store table. The store has 3 columns:

  • StoreID (int) (PK)
  • Name (nvarchar)
  • Link FlyerID (int) (FK) to the Flyer Table

Now, on the DynamicData site, I will have a Shops page and a Flyers page. I want to display FlyerDate using my own format. For example, the format is MMM-dd-yyyy.

On the Flyers page, the method that I followed after the tutorial video at: asp.net/learn/3.5-SP1/video-291.aspxworks fine by displaying my custom format for the FlyerDate column.

However, on the Stores page, the Flyer column values ​​(which are hyperlinks) do not show the date in my custom format. In addition, the custom format is not displayed in the Filter drop-down list.

The proposed unsuccessful solution: http://ericphan.info/development/asp-net-dynamic-data-display-custom-text-in-a-foreign-key-dropdownlist-combobox gives the error "DisplayDate column specified for the table, does not exist."

.Net Framework 4.0 BETA and Entity Framework.

[DisplayColumn("DisplayDate", "FlyerDate", true)]
[MetadataType(typeof(FlyerMetadata))]
public partial class Flyer
{

    [ScaffoldColumn(true)]
    public string DisplayDate
    {
        get { return this.FlyerDate.ToString("MMM-dd-yyyy"); }
    }

}

public class FlyerMetadata
{
    [DisplayFormat(ApplyFormatInEditMode = true, DataFormatString = "{0:MMM-dd-yyyy}")]
    public DateTime FlyerDate { get; set; }
}
+3
2

, . ToString:

public partial class Flyer
{

    public override string ToString()
    {
        return this.FlyerDate.ToString("MMM-dd-yyyy");
    }

}
+1

DisplayDate , :

public class FlyerMetadata
{
    public String DisplayDate { get; set; }
}
+1

Source: https://habr.com/ru/post/1728675/


All Articles