Caching with filtration:
private void Bind()
{
try
{
DataSet DS_district = new DataSet();
DataTable _table = new DataTable();
if (Cache["CachingName"] == null)
{
DS_district = Common.GetAllDistrict();
SqlCacheDependency dependency = new SqlCacheDependency ("DataBaseName", "TableName");
Cache.Insert("CachingName", DS_district, dependency, System.Web.Caching.Cache.NoAbsoluteExpiration, TimeSpan.FromMinutes(10));
_table = DS_district.Tables[0];
var query = from _district in _table.AsEnumerable()
where _district.Field
select _district;
DataView _view = query.AsDataView();
Dropdown1.DataSource = _view;
Dropdown1.DataTextField = "Name";
Dropdown1.DataValueField = "Id";
Dropdown1.DataBind();
}
else
{
DS_district = (DataSet)Cache["CachingName"];
_table = DS_district.Tables[0];
var query = from _district in _table.AsEnumerable()
where _district.Field
select _district;
DataView _view = query.AsDataView();
Dropdown1.DataSource = _view;
Dropdown1.DataTextField = "GeographicName";
Dropdown1.DataValueField = "GeographicId";
Dropdown1.DataBind();
}
}
catch (Exception ex)
{
lblError.Text = ex.Message.ToString();
}
}
No comments:
Post a Comment