Click here to Skip to main content
15,908,274 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi
I have this event that suppose to load gridview according to the selected date.
When I commented the code to populate the gridview, the messagebox appear with the correct values. This means al the necessary values to populate the gridview are available.

when i uncomment the code to populate the grid,the grid dont work...what might be the problem. Check the code below...

C#
protected void ddlEmployeeID_SelectedIndexChanged(object sender, EventArgs e)
      {
          getEmployeeId();
          try
          {
              string date = DateTime.Now.ToShortDateString();
              //string selectedDate = DatePicker.SelectedDate.ToShortDateString();
              if (DatePicker.SelectedDate.ToShortDateString() == date || DatePicker.SelectedDate.ToShortDateString() == "1/1/0001")
              {
              if (Page.IsPostBack)
              {
                  DataTable dt = new DataTable();
                  systemBusinessLayer = new BusinessLayer();
                  dt = new DataTable();
                  dt = systemBusinessLayer.getAllEmployeeAppointmentsByDate(date, Session["idnumber"].ToString());
                  grdShowSelectedappointment.DataSource = dt;
                  grdShowSelectedappointment.DataBind();
              //MessageBox.Show(date + " " + Session["idnumber"].ToString() + " " + "Am using default dates");//date + " " + Session["idnumber"].ToString() + " " + "Am using default dates"
              }
              }
              else
              {
                  //DataTable dt = new DataTable();
                  //systemBusinessLayer = new BusinessLayer();
                  //dt = new DataTable();
                  //dt = systemBusinessLayer.getAllEmployeeAppointmentsByDate(DatePicker.SelectedDate.ToShortDateString(), Session["idnumber"].ToString());
                  //grdShowSelectedappointment.DataSource = dt;
                  //grdShowSelectedappointment.DataBind();
                  MessageBox.Show("Am using selected date");
              }
              // MessageBox.Show(var);
          }
          catch (Exception)
          {
          }

      }
Posted
Comments
walterhevedeich 21-Jul-11 4:28am    
By saying the grid wont work, do you mean it throwed errors? Or there was no data?
Anele Ngqandu 21-Jul-11 4:30am    
It doesnt show anything,no error, nothing

1 solution

IF I look at your code, I suspect your code should be:
protected void ddlEmployeeID_SelectedIndexChanged(object sender, EventArgs e)
{
  getEmployeeId();
  try
  {
    string date = DateTime.Now.ToShortDateString();
    string selectedDate = DatePicker.SelectedDate.ToShortDateString();
    systemBusinessLayer = new BusinessLayer();
    DataTable dt = new DataTable();
    if (Page.IsPostBack && DatePicker.SelectedDate == DateTime.MinValue)
    {
        dt = systemBusinessLayer.getAllEmployeeAppointmentsByDate(date, Session["idnumber"].ToString());
    }
    else
    {
        dt = systemBusinessLayer.getAllEmployeeAppointmentsByDate(DatePicker.SelectedDate.ToShortDateString(), Session["idnumber"].ToString());
    }
    grdShowSelectedappointment.DataSource = dt;
    grdShowSelectedappointment.DataBind();
  }
  catch (Exception error)
  {
        String exception == error.ToString();  // for debug purposes
  }

}
 
Share this answer
 
v2
Comments
Anele Ngqandu 21-Jul-11 6:19am    
no sir its not working
Herman<T>.Instance 21-Jul-11 8:42am    
where it fails?

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