Click here to Skip to main content
16,004,564 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Below is the method that loads date in a session

C#
protected void getDayOfWeek(int selectedDay)
        {
           if ((int)DateTime.Now.DayOfWeek >= selectedDay || (int)DateTime.Now.DayOfWeek <= selectedDay)
            {
                Session["SelectedDay"] = DateTime.Now.AddDays(-((int)DateTime.Now.DayOfWeek - selectedDay)).ToShortDateString();
            }
        }


Now below is an event, so i want to use the session above to reload a gridview but it appears that the session is empty for some reasons that i dont know , i get this error "Object reference not set to an instance of an object."

C#
protected void ddlEmployeeID_SelectedIndexChanged(object sender, EventArgs e)
        {
                       DataTable dTable = new DataTable();
                       dTable = systemBusinessLayer.GetAllEmployeesInfo();
            foreach (DataRow dRow in dTable.Rows)//Go through each row inside datatable
            {
                string empIDNumber = dRow["Fullname"].ToString();
                if (ddlEmployeeID.SelectedItem.Text == empIDNumber)
                {
                    Session["idnumber"] = dRow["EmpRecNumber"].ToString();
                                  
               }
              
loagrvSlots(Convert.ToInt32(Session["idnumber"]), Session["SelectedDay"].ToString());
            }
           
        
        }
Posted
Updated 17-Sep-11 3:03am
v3
Comments
Herman<T>.Instance 17-Sep-11 9:06am    
what's in the method loagrvSlots?
and what if ddlEmployeeID.SelectedItem.Text != empIDNumber? your session["IDNumber"] is in that case NULL!
Please show your error trace
Anele Ngqandu 17-Sep-11 9:16am    
Ok no sorry i hav found my solution, i needed to select a date to fill thiis Session["SelectedDay"]

1 solution

Your if condition is useless: it will be untrue for a very, very brief time around midnight.

Are you sure that the problem is your Session["SelectedDay"]? Have you checked? Because it could be Session["idnumber"] instead...

I would start by checking both and work back from there.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900