Use computed property as DisplayColumn in ASP.Net dynamic data?

I am trying to display a "Software Release" table on an asp.net dynamic data site. The Release table has an assembly number, which is stored as three int fields (Major, Minor, Build). I use EntityFramework, so I have an EF model attached to my database schema. On my dynamic data site, I want the build number to appear as a single field (Major.Minor.Build) wherever the Release object is shown (especially when it appears as a foreign key on pages for related objects). Since this "computed column" is not a field in my database, it looks like it is all the same for Dynamic-Data to recognize or display it. I can add a property to the Release object (since it is a partial class generated by EF), but Dynamic-Data does not recognize it because it is not a "column".I want to edit Release as three separate fields (major, minor, build), but when it is displayed, I want it to be shown as one field. The DynamicData frame does not seem to support composite fields, and it will not display / bind to object properties if they are not in the EF model. How do I make the property of the formatted version number display the default value?

+3
source share
2 answers

I'm not sure if you are binding to the DataTable / DataSet returned from the database, or if you are binding to the Release object itself. Not a single control.

If you bind to a DataSet / DataTable, just change your SQL to return the version as a single field:

SELECT table1.Major + '.' + table1.Minor + '.' + table1.Build AS Version ....

However, if you bind to an object, say DropDownList, I think that if you override the ToString method, it will become the display value in DropDownList:

Public Overrides Function ToString() As String
    Return _major.ToString & '.' & _minor.ToString & '.' & _build.ToString
End Sub
+3
source

, ui. UIHint , , . .

[MetadataType(typeof(EMetadata))]
public partial class E{


    public string RefNR {
        get {
            return "E" + this.EntryID.ToString().PadLeft(5, '0');
        }
    }

}

public partial class EMetadata {
    [UIHint("Text")]
    public object RefNR;
}
+4

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


All Articles