检查从日期和Gridview行选择日期我尝试但它不工作

问题描述:

我的代码如下



My code as follows

DateTime selectedfromdate = Convert.ToDateTime(Txtfromdate.SelectedDateValue);

for (int i = 0; i < GvSch.Rows.Count; i++)
{
   GridViewRow rows = GvSch.Rows[i];
   if (selectedfromdate == rows.Cells[0].Text.ToString().Trim())
   {
      Lblerr.Text = "selected date and excel sheet should be same";
      return;
   }
}



当我运行时显示错误如下




When i run shows error as follows

Operator == cannot be applied to operands of type 'System.date.time' and 'String'



从上面的代码中可以看出什么是错误的我发了吗?



请帮帮我。



问候,

Narasiman P


From my above code what is the misktake i made?

please help me.

Regards,
Narasiman P

尝试下面的代码

Try the below code
if (selectedfromdate.ToShortDateString().equals(rows.Cells[0].Text.ToString().Trim()))
{
    Lblerr.Text = "selected date and excel sheet should be same";
    return;
}