In a word, yes, it is possible. However, I do not believe this is a good idea. What you are really talking about is storing presentation data in your database, when really the best place to put this is in your aspx pages themselves. That being said, if you want to store data dictionary type information in your DB, I'd recommend making use of the built in sys.tables
, sys.columns
, and sys.types
views that are built into MS SQL Server, and adding a table called ObjectDescriptions
to store the display name and type.
create table ObjectDescriptions (
object_id int not null,
column_id null, --leave this column null if the record describes the table itself
ObjectDisplayName nvarchar(20),
ObjectDescription nvarchar(200)
);
Then, you could create a view based on object ID to retrieve the meta data of your table, and either directly bind or dynamically populate your asp.net FormView
.
create view TableData as
select
t.name as table_name
,td.ObjectDisplayName as table_display_name
,td.ObjectDescription as table_description
,c.name as column_name
,cd.ObjectDisplayName as column_display_name
,cd.ObjectDescription as column_description
,c.column_id
,ty.name as [type_name]
,c.max_length
,c.scale
,c.[precision]
from sys.tables t
left join ObjectDescriptions td on td.object_id = t.object_id
join sys.columns c on c.object_id = t.object_id
left join ObjectDescriptions cd on cd.column_id = c.column_id and cd.object_id = c.object_id
join sys.types ty on c.user_type_id = ty.user_type_id
EDIT:
You can then leverage this view in your ASP code by writing a class that holds your meta data about a single table, and writing a method in your DAL to retrieve an instance of this class based on object or table name. When you populate your page, the page could retrieve both the record you are looking for, as well as the table's meta-data, and bind that meta data to either grid headers (in list view) or to individual label's accompanying text boxes in single record mode.