How to create a custom property editor in asp.net (web forms)
Say we have this structure in db, with almost none properties. All properties, their name, default value, description and type (string, integer, datetime) are defined in one table (attributeDefinition), and all values are stored in another table.
Cars (Id, Name)
AttributeDefinition(AttributeDefinitionId, Typ开发者_运维百科e, Name, Desctiption, MaxValue, ...)
AttributesValues (AttributeDefinitionId, CarId, Value)
Now I want to create a generic editor for the Cars properties.
Question is, how should I implement this? Are there some build in controls that can handle this, are there something similar other have been doing?
Or should I just go like this:
// In MyPropertyEditor.ascx load
// Iterate over all attributes in attributedefinition
// add TextBox, NumberEditor or DateTimePicker,
// give them som good names
// End
//
// In Save, iterate over all controls again, and save back
Am I heading in the right direction?
I was thinking about the datagrid, and how it creates all the columns on the fly. I was hoping I could do something similar?
Thanks for any help
Regards
Larsi
Are you talking support inside Visual studio? If you are:
Here are some of the options for handling this: http://msdn.microsoft.com/en-us/magazine/cc164048.aspx In its simplest form, setting up a TypeConverter would get the job done, but if you want a custom UI form, you have to look at creating a custom editor.
If not, but talking a UI for building a web site, you could consider dynamic data as that is what it's meant for - a quick easy way to build UI's for your data and its relationships. There may be some components that you can use even in a web forms project...
HTH.
精彩评论