views:

80

answers:

2

Hi, We are working on an ASP.NET application. It has 3- 4 forms displaying country list dropdown. Here we would like to avoid binding these dropdowns each time by getting data from database. Instead looking for a better practice of binding it one time, say on application load/some other.

Would you please let me know how we could go head on this? Any reference link or document would be great.

Many Thanks, Regards, Nani

A: 

Place the drop down in a user control and enable output caching on the user control.

This solution cause the rendered HTML to be cached so the databinding won't need to be called on every page request.

Bob
If you are using an ObjectDataSource or SqlDataSource to bind the drop-down control to you can also enable caching on the data source control.
Yadyn
A: 

Another possibility would be to use some caching mechanism on your BL logic. For instance in your page/usercontrol you could have (don't take my syntax too strict ;) )

public partial class MyPaged: Page {

public void PageLoad(..) {

  if(!IsPostBack)
  {
     dropDownCountries.DataSource = CountryBL.GetCountries();
     dropDownCountries.DataBind();
  }
  ...

}

}

and in your business logic class you do some kind of caching where you may have a singleton class that holds the countries and functions as your cache. A pseudocode method could be

public IList<Country> GetCountries
{
   //if the cache is empty or it should be refreshed, fills the local 
   //list of countries, i.e. the cache, with fresh entries from the DB
   //there could be some time condition, i.e. refresh every day or so
   EnsureCacheValid();

   return CachedCountries; //the cache of countries
}

This could be another option with the advantage that your presentation logic doesn't even know about the caching and if you would add a webservice access or so, you would also benefit from the caching. The only thing you have to pay attention at is if there is the possibility that the user can change the countries (which in your example I don't suppose).

Juri