如果时间小于当前时间,如何禁用chekbox [英] how to disable chekbox if time is less than current time

查看:94
本文介绍了如果时间小于当前时间,如何禁用chekbox的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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我有预约时间在gridview中小于当前时间或者我希望该约会不应该被预订。或者想要禁用该chekbox。我已经写了其他条件,但是它没有进入那个条件。它只显示启用。请帮助我。



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.

推荐答案

你好,< br $>


您需要使用 DateTime 。比较方法。

Hi,

You need to use DateTime.Compare method.
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.


这篇关于如果时间小于当前时间,如何禁用chekbox的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆