ASP.NET Configurable User Control

Garnachito

New Member
I have a question regarding the approach I am taking in solving following scenario is correct / efficient or not ?Platform: ASP.NET 3.5 / 4.0 Language C#I have a Page which do Product Listing and the Product Listing is handled via User Control.That Control is having Sorting, Paging and DisplayMod ( Gridview, Listview ) like functionality.We wanted to Control which attributes / Values will be available to User via Admin Module.Like which options will available to user for Sorting out of possible Values e.g. { Sort By Name / Sort By Price / Sort by Availability }or In case of Display: Either Gridview / Listview or Both.for this purpose we have Defined Properties in our UserControl with Enums likePlease note, this code is for illustration purpose only.\[code\]public partial class ProductListUserControl : System.Web.UI.UserControl{public enum SortByOptions{ Name, Price ASC, Price Desc, Availability}SortByOptions _SortByOptions;public SortByOptions SortByOptionsProp{ get { return _SortByOptions;} set { _SortByOptions;= value; }}.....}\[/code\]Now we want to Control this Controls behaviour thorugh AdminSo on Admin side we have a code like this\[code\]ProductListUserControl productListUserControl = new ProductListUserControl();foreach (var pi in productListUserControl.GetType().GetProperties()){ var name = pi.Name; var type = pi.PropertyType; // Get Property Values MemberInfo[] memberInfos = pi.PropertyType.GetMembers(BindingFlags.Public | BindingFlags.Static); string sortValues = string.Empty; for (int i = 0; i < memberInfos.Length; i++) { sortValues += memberInfos.Name + " \n "; } }\[/code\]Our Approach is to Show all the Possible Values for the Properties Like SortByOptionsPropAdmin will select from those vailable Options and then according to those selected Options the UserControl i.e. ProductListUserControl in our Case will render the Appropriate Section like Sorting or DisplayMod etc.Is this the correct approach ? I am not sure and that is why I am asking here,hoping someone will guide me to a better way of achieving the same functionality.Thank you all, in Advance.
 
Back
Top