developer155
Programmer
Hi,
I am binding DataGrid to a dataview from a DataTable retrieved from Cache. When cache is empty and dataset is retrieved for the first time from DB everything is fine and the datagrid shows.
Now when I get the dataset from cache and bind it to datagrid, grid show up empty! I iterated through data set and it looks like the data is there after I retrieve it from cache. Thanks for any tips:
Here is code:
public static DataSet GetCatalog()
{
DataSet Catalog=null;
if(HttpContext.Current.Cache["Catalog"]!=null)
{
Catalog = (DataSet)HttpRuntime.Cache["Catalog"];
}
else
{
//get from database and put in cache
Catalog = ZoyaModaDP.LoadCatalog();
//store in Cache for an hour
HttpRuntime.Cache.Insert("Catalog",Catalog,null,DateTime.Now.AddMinutes(60),TimeSpan.Zero);
}
//test
DataView dv=Catalog.Tables["Category"].DefaultView;
foreach (DataRow row in dv.Table.Rows)
{
string test = row["Name"].ToString();
string test2 = test;
}
return Catalog;
}
Here is code from aspx page:
DataSet Catalog = GetCatalog();
CategoryDataGrid.DataSource = Catalog.Tables["Category"].DefaultView;
CategoryDataGrid.DataBind();
I am binding DataGrid to a dataview from a DataTable retrieved from Cache. When cache is empty and dataset is retrieved for the first time from DB everything is fine and the datagrid shows.
Now when I get the dataset from cache and bind it to datagrid, grid show up empty! I iterated through data set and it looks like the data is there after I retrieve it from cache. Thanks for any tips:
Here is code:
public static DataSet GetCatalog()
{
DataSet Catalog=null;
if(HttpContext.Current.Cache["Catalog"]!=null)
{
Catalog = (DataSet)HttpRuntime.Cache["Catalog"];
}
else
{
//get from database and put in cache
Catalog = ZoyaModaDP.LoadCatalog();
//store in Cache for an hour
HttpRuntime.Cache.Insert("Catalog",Catalog,null,DateTime.Now.AddMinutes(60),TimeSpan.Zero);
}
//test
DataView dv=Catalog.Tables["Category"].DefaultView;
foreach (DataRow row in dv.Table.Rows)
{
string test = row["Name"].ToString();
string test2 = test;
}
return Catalog;
}
Here is code from aspx page:
DataSet Catalog = GetCatalog();
CategoryDataGrid.DataSource = Catalog.Tables["Category"].DefaultView;
CategoryDataGrid.DataBind();