Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations wOOdy-Soft on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Store in XML or as an enum

Status
Not open for further replies.

Craftor

Programmer
Feb 1, 2001
420
NZ
Hi all

I've got a 'best practice' question here.

I've got several dropdown lists on a web application to allow the user to select various options e.g. Title (Mr, Mrs etc.). The application should be easy to update and we cannot use a database to store the values.

What would be the best option to use? A set of predefined options in code or storing the values in an XML file?

Thanks as always

Craftor
:cool:
 
I'd use neither barring other factors.

The easiest way to approach your specific problem would be to create a set of User Controls, each containing a DropDownList that you populate with ListItems in the designer.

The alternate approaches require extra data access code, and/or limit your formatting options (enums can't have spaces or periods, for example).

MCP, MCTS - .NET Framework 2.0 Web Applications
 
I'd have a look at how often the data is going to change. With titles for a person, there is probably a pre-defined list that you can use which will never change. On the other hand, if it's for something that may change frequently, and you can't use a database, I'd say that the XML file would be a good choice.


____________________________________________________________
Mark,
[URL unfurl="true"]http://aspnetlibrary.com[/url]

Need help finding an answer? Try the Search Facility or read FAQ222-2244.
 
Thanks for both of these ideas. I think I'm going to go for a combination of XML (for the items that are likely to change) and enums (for my static lists).





Craftor
:cool:
 
caching would be your best option, no matter where the data comes from.
Code:
public class NamePrefixManager
{
   public NameValuePairCollection GetLookupValues()
   {
      //fetch data
      return new NameValuePairCollection();
   }
}

public class NamePrefixCacheManager
{
   private Cache cache;

   public NamePrefixCacheManager()
   {
      cache = HttpContext.Cache.Current;
   }

   public NameValuePairCollection GetLookupValues()
   {
      NameValuePairCollection toReturn = (NameValuePairCollection) this.cache["NamePrefix"];
      if(toReturn == null)
      {
         toReturn = new NamePrefixManager().GetLookupValues();
         this.cache["NamePrefix"] = toReturn;
      }
      return toReturn;
   }
}

then in the code behind access the NamePrefixCacheManager.
Code:
protected void Page_Load(object sender, EventArgs e)
{
   if (!this.IsPostback)
   {
      this.MyDropDown.DataSource  = new NamePrefixCacheManager().GetLookupValues();
      this.MyDropDown.DataBind();
   }
}
Of course there are numerous ways to implement this You as easily wrap the NamePrefixManager with a CacheManager or extend the NamePrefixManager to use a CacheManager.

if your values have any chance of changing and not creating a system wide impact then I would use xml. this way you can add. a new lookup value without recompiling the system.

if your lookups effect business logic. (like order status: pending, received, fulfilled, shipped, invoiced.) then an enum would be a valid option. If you need to add a new status then your changing logic in your system which will require modified code.

Jason Meckley
Programmer
Specialty Bakers, Inc.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top