public string Get_Date()
{
try
{
Convert.ToDateTime(DropDownList1.SelectedValue+"/"+DropDownList2.SelectedValue+"/"+DropDownList3.SelectedValue);
}
catch (Exception e)
{
DropDownList1.SelectedValue=DateTime.Today.Year.ToString();
DropDownList2.SelectedIndex=0;
DropDownList3.SelectedIndex=0; return "";
} if ((DropDownList1.SelectedIndex==0) ||(DropDownList1.SelectedIndex==0)||(DropDownList1.SelectedIndex==0))
{
return "";
}
else
{
return (DropDownList1.SelectedValue+"/"+DropDownList2.SelectedValue+"/"+DropDownList3.SelectedValue); }
}
{
try
{
Convert.ToDateTime(DropDownList1.SelectedValue+"/"+DropDownList2.SelectedValue+"/"+DropDownList3.SelectedValue);
}
catch (Exception e)
{
DropDownList1.SelectedValue=DateTime.Today.Year.ToString();
DropDownList2.SelectedIndex=0;
DropDownList3.SelectedIndex=0; return "";
} if ((DropDownList1.SelectedIndex==0) ||(DropDownList1.SelectedIndex==0)||(DropDownList1.SelectedIndex==0))
{
return "";
}
else
{
return (DropDownList1.SelectedValue+"/"+DropDownList2.SelectedValue+"/"+DropDownList3.SelectedValue); }
}
定义的是public string Get_Date();
但实现时是Convert.ToDateTime(DropDownList1.SelectedValue+"/"+DropDownList2.SelectedValue+"/"+DropDownList3.SelectedValue);
请问我到底得到的是个字符串类型呢,还是个日期类型呀。
我用这个涵数的值进行比较时,提示字符串类型不能进行比较。
我用Convert.ToDateTime将它转化再进行比较。断点时提示Convert.ToDateTime=<overloaded>,
各位老大帮忙指点迷津。看应该怎么办。我郁闷死了。
我是在网页上放置了两个这样的控件,并把它们的Get_Date()值进行比较,却不成功。
希望继续指教。
{
return (DropDownList1.SelectedValue+"/"+DropDownList2.SelectedValue+"/"+DropDownList3.SelectedValue); }
这里返回的是一个字符串,如果你有两个这样的日期控件,得到的其实都是字符串,所以它们并没有按日期进行比较。
是不是本身这个涵数写得有问题?
{
Convert.ToDateTime(DropDownList1.SelectedValue+"/"+DropDownList2.SelectedValue+"/"+DropDownList3.SelectedValue);
}
----------------------------------
这句得到的是一个DateTime对象,但并没起到任何作用。因为后来根本没有用到它,也没作为返回值返回。