Dynamically adding webpart properties
-
I have a webpart that displays departmental news. Every department have different news section for instance Admin dept have three news section: 1- Admin 2- HR 3- General Sales dept have four: 1- Company Sales News 2- Stock News 3- Global Market News 4- Sales Forecast Now, I want to expose these sections as properties of my WebPart so if a Sales user is logged in; when he will enter Edit Mode; he sees all four sections in Sales Dept and from which he can choose what all it is that he wants to see on the webpart. I can hardcode something like this:
protected bool _CompanySales = true; [ Personalizable(PersonalizationScope.User), WebBrowsable, WebDisplayName("Company's Sales News"), WebDescription("Use this property to show/hide Company's Sales news")] public bool CompanySales { get { return _CompanySales ; } set { _CompanySales = value; } } protected bool _StockNews= true; [ Personalizable(PersonalizationScope.User), WebBrowsable, WebDisplayName("Stock News"), WebDescription("Use this property to show/hide Stock News")] public bool StockNews{ get { return _StockNews; } set { _StockNews= value; } } protected bool _GlobalMarketNews= true; [ Personalizable(PersonalizationScope.User), WebBrowsable, WebDisplayName("Global Market News"), WebDescription("Use this property to show/hide Global Market News")] public bool GlobalMarketNews{ get { return _GlobalMarketNews; } set { _GlobalMarketNews= value; } } // ... // ETC
But I wouldn't have any knowldge of these sections because they are stored in the database. So I guess my question is; how can I dynamically define properties of a webpart by pulling the data from a datasource? Thanks in advance.