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); }
}

解决方案 »

  1.   

    感觉有点四不象。
    定义的是public string Get_Date();
    但实现时是Convert.ToDateTime(DropDownList1.SelectedValue+"/"+DropDownList2.SelectedValue+"/"+DropDownList3.SelectedValue);
    请问我到底得到的是个字符串类型呢,还是个日期类型呀。
    我用这个涵数的值进行比较时,提示字符串类型不能进行比较。
    我用Convert.ToDateTime将它转化再进行比较。断点时提示Convert.ToDateTime=<overloaded>,
    各位老大帮忙指点迷津。看应该怎么办。我郁闷死了。
      

  2.   

    Convert.ToDateTime 是转换成DateTime对象。当然不能和String直接比较。((DropDownList1.SelectedIndex==0) ||(DropDownList1.SelectedIndex==0)||(DropDownList1.SelectedIndex==0))这怎么都是 DropDownList1 ?
      

  3.   

    这是个用三个DropDownList组合成的日历控件。
    我是在网页上放置了两个这样的控件,并把它们的Get_Date()值进行比较,却不成功。
    希望继续指教。
      

  4.   

    如果选择了日期 程序最后执行的应该是这段代码:else
       {
            return                                                                        (DropDownList1.SelectedValue+"/"+DropDownList2.SelectedValue+"/"+DropDownList3.SelectedValue);   }
    这里返回的是一个字符串,如果你有两个这样的日期控件,得到的其实都是字符串,所以它们并没有按日期进行比较。
      

  5.   

    但是为什么当我用CONVERT.ToDateTime进行转化时又提示Convert.ToDateTime=<overloaded>?
    是不是本身这个涵数写得有问题?
      

  6.   

    try 
    {
    Convert.ToDateTime(DropDownList1.SelectedValue+"/"+DropDownList2.SelectedValue+"/"+DropDownList3.SelectedValue);
    }
    ----------------------------------
    这句得到的是一个DateTime对象,但并没起到任何作用。因为后来根本没有用到它,也没作为返回值返回。
      

  7.   

    那为什么用CONVERT.ToDateTime时会提示Convert.ToDateTime=<overloaded>?