Click here to Skip to main content
15,888,208 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
C#
protected void grdbookstatus_RowDataBound1(object sender, GridViewRowEventArgs e)
        {
            DataTable dt =(DataTable)ViewState["dt"];
            DateTime indianTime = TimeZoneInfo.ConvertTimeFromUtc(DateTime.UtcNow, INDIAN_ZONE);
            if (e.Row.RowType == DataControlRowType.DataRow)
            {
              
                CheckBox chk = (CheckBox)e.Row.FindControl("CheckBox1");
                Label lbl = (Label)e.Row.FindControl("Label2");
                Label lblpname = (Label)e.Row.FindControl("lblpname");
                if (dt.Rows.Count > 0)
                {
                    for (int i = 0; i < dt.Rows.Count; i++)
                    {


                        if (chk.Text == Convert.ToString(dt.Rows[i]["AppointmentTime"]))
                        {
                            chk.Checked = true;
                            chk.Enabled = false;
                            lbl.Text = "Booked";
                            lblpname.Text = Convert.ToString(dt.Rows[i]["Patient_Name"]);
                            e.Row.Cells[1].ForeColor = System.Drawing.Color.Blue;
                            e.Row.Cells[2].ForeColor = System.Drawing.Color.Blue;
                            e.Row.Cells[3].ForeColor = System.Drawing.Color.Blue;
                            e.Row.BackColor = System.Drawing.Color.Red;
                            break;
                        }
                       // else if (Convert.ToString(dt.Rows[i]["AppointmentTime"]) > indianTime)
                        else if (Convert.ToDateTime(dt.Rows[i]["AppointmentTime"]).Hour > indianTime.Hour)
                        {
                            chk.Enabled = false;
                        }
                        else 
                        {
                            lbl.Text = "Available";
                          //  Button1.Visible = false;
                         
                        }
                    }
                }
                else
                {
                    lbl.Text = "Available";
                    imgwlkin.Visible = false;
                    
                }

            }
        }


i am having appointment time in gridview is less than current time or then i want that appointment should not get booked.or want to disable that chekbox. i have written else if condition for that..but it is not going inside that condition.and it is showing enable only.please help me.
Posted
Updated 4-Apr-13 1:14am
v2
Comments
Ankur\m/ 4-Apr-13 5:39am    
Put a debugger and see what's wrong.

1 solution

Hi,

You need to use DateTime.Compare method.
C#
DateTime date1 = new DateTime(2009, 8, 1, 0, 0, 0);
DateTime date2 = new DateTime(2009, 8, 1, 12, 0, 0);
int result = DateTime.Compare(date1, date2);
string relationship;

if (result < 0)
   relationship = "is earlier than";
else if (result == 0)
   relationship = "is the same time as";         
else
   relationship = "is later than";

Console.WriteLine("{0} {1} {2}", date1, relationship, date2);
// The example displays the following output: 
//    8/1/2009 12:00:00 AM is earlier than 8/1/2009 12:00:00 PM


Good luck.
 
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