In the aspx.cs page- I have the method to populate the dropdownlist:
protected void populate_DeptID()
{
DropDownList ddl_DeptID = new DropDownList();
ddl_DeptID = dvEmployee.FindControl("lstDeptID") as DropDownList;
if (Cache["get_DeptID"] != null)
{
ddl_DeptID.DataSource = Cache["get_DeptID"];
}
else
{
employeeDetails DeptID = new employeeDetails();
DataTable dt_DeptID = new DataTable();
dt_DeptID = (DeptID.GetDeptID()).Tables[0];
Cache["get_DeptID"] = dt_DeptID;
//Cache.Insert("dt_DeptID", dt_DeptID);
//dt_DeptID = Cache["dt_DeptID"] as DataTable;
ddl_DeptID.DataSource = dt_DeptID;
}
}
In the design page:I have a detail view,inside which is present the dropdownlist which appears in the edit mode of the detail view. The query to return the values for the dropdownlist is present in the DAL.populate_DeptID() populates the dropdownlist .But
while executing I encounter an error "Nullreference exception" at statement "ddl_DeptID.DataSource = dt_DeptID;". The Cache has the values but once it encounter this line,it throws this exception.Can anyone tell me why?
Jasmine29
Member
18 Points
45 Posts
Help needed to resolve error related to Cache
Mar 27, 2008 02:39 PM|LINK
Hi,
In the aspx.cs page- I have the method to populate the dropdownlist:
protected void populate_DeptID()
{
DropDownList ddl_DeptID = new DropDownList();
ddl_DeptID = dvEmployee.FindControl("lstDeptID") as DropDownList;
if (Cache["get_DeptID"] != null)
{
ddl_DeptID.DataSource = Cache["get_DeptID"];
}
else
{
employeeDetails DeptID = new employeeDetails();
DataTable dt_DeptID = new DataTable();
dt_DeptID = (DeptID.GetDeptID()).Tables[0];
Cache["get_DeptID"] = dt_DeptID;
//Cache.Insert("dt_DeptID", dt_DeptID);
//dt_DeptID = Cache["dt_DeptID"] as DataTable;
ddl_DeptID.DataSource = dt_DeptID;
}
}
In the design page:I have a detail view,inside which is present the dropdownlist which appears in the edit mode of the detail view. The query to return the values for the dropdownlist is present in the DAL.populate_DeptID() populates the dropdownlist .But while executing I encounter an error "Nullreference exception" at statement "ddl_DeptID.DataSource = dt_DeptID;". The Cache has the values but once it encounter this line,it throws this exception.Can anyone tell me why?
Rgds