I have a FormView on a ASP.Net Webform along with a ObjectDataSource.
Now, the data that I want to display and allow edit is as follows:
Unique way to access all these properties: Organization ID
Company from DB
LDAP Server from/to DB, a KeyValuePair-like table
Domain Name from/to DB, a KeyValuePair-like table
Use DHCP from/to DB, a KeyValuePair-like table
IP Address from/to WMI utility class, no storage in DB
Subnet Mask from/to WMI utility class, no storage in DB
So, I need to somehow create an Entity of type… umm… SystemSetting at runtime and feed it to the ObjectDataSource and it’ll take care of FormView food-source. Upon Edit, i need to switch to edit mode and upon update, i need to retrieve the values/SystemSetting entity and manually dispatch the value to their respective places.
Now I’m never going to create a new entity. It always display and update. And there is always one entity.
That’s theory. Any quick pointers? Thanks.
The simplest solution is to just create a
SystemSettingclass with public auto properties of the types you mentioned, then make aList<SystemSetting>out of it, and feed that to theObjectDataSource(if your tables don’t have a fixed length, then use a foreach loop to add controls for them onDataBindingevent).On edit, if your tables have a fixed length, then just two-way databind everything and you’re all set, you’ll automagically get an updated
SystemSettingclass for yourObjectDataSourceupdate method.If not, then just handle the updating event yourself (specify a phantom update method for
ObjectDataSourceand cancel it right then), read input fields one by one (group them under a separate container for each table, or let them share a prefix or suffix for id, so you know where they belong), and dispatch the values to their respective places.You’ll have to provide some more details, or better yet a code sample, for a more complete solution.