ga该字符串未被识别为有效的 DateTime

来源:百度知道 编辑:UC知道 时间:2024/06/01 19:42:39
string hotalName = txtHotalName.Text;
DateTime InTime =DateTime.Parse(Convert.ToDateTime(txtInTime.Text).ToString("yyyy-MM-dd"));
DateTime OutTime = DateTime.Parse(Convert.ToDateTime(txtOutTime.Text).ToString("yyyy-MM-dd"));
decimal price = Convert.ToDecimal(ddlPrice.SelectedValue);
string star = ddlStar.SelectedValue;
Response.Redirect("SearchResult.aspx?cityID="+cityID+"&hotalName='"+hotalName+"'&InTime='"+InTime+"'&OutTime='"+OutTime+"'&price="+price+"&star="+star+"");
这段代码报该字符串未被识别为有效的 DateTime错误,为什么啊?
在另一个页面我是通过Datasourse绑定到datalist的,代码是:
<asp:QueryStringParameter Name="cityID" QueryStringField="cityID" Type="Int32" DefaultValue="0" />
<asp:QueryStringParameter Name="hotalName" QueryStringField="hotalName" Type=&

Response.Redirect("SearchResult.aspx?cityID="+cityID+"&hotalName='"+hotalName+"'&InTime='"+InTime+"'&OutTime='"+OutTime+"'&price="+price+"&star="+star+"");
这一段.

InTime 和 OutTime 是DateTime 类型.
那么你拼接到 String 当中的时候需要转换成String 类型。
比如你上面的
InTime.ToString("yyyy-MM-dd");
OutTime.ToString("yyyy-MM-dd");