asp.net - Fill Dropdown in asp dotnet from Caching -
i have dropdown in asp.net fills agent list. agent list 30,000. want keep data in cache dont need fill dropdown again , again database. how achieve caching. please guide
suppose have cache
varriable, have convert datatable
,
datatable tblcategories = (datatable) cache["categories"];
and , check, if still datatable empty, fetch database using loadcategoryindropdownlist()
function takes data databse.
if (tblcategories == null) { tblcategories = new datatable(); tblcategories=objdac.loadcategoryindropdownlist(); // inserts new row in filled datatable. //this new row contains static data user //instruction text such as" select item" datarow dr=tblcategories.newrow(); dr["categoryid"]=0; dr["categoryname"]="--select item--"; tblcategories.rows.insertat(dr,0); //cache datatable in cache memory duration of 1 hour... cache.insert("categories", tblcategories, null, datetime.now.addhours(1), cache.noslidingexpiration); }
then bind dropdown datatable
dropdownlist1.datasource = tblcategories dropdownlist1.datatextfield ="a descriptive field table"; dropdownlist1.datavaluefield="a key / value field table"; dropdownlist1.databind();
you can refer here http://www.codeproject.com/articles/10033/a-generic-loading-of-data-in-a-dropdownlist-using
Comments
Post a Comment