私は割り当てを苦労して、終了日がASP.NETのC#の開始日より後でなければならないことを確認するようにしました。先生は言います:日付チェッカーのIF文
Create an If statement to check that both start and end date exist as COMPOUND condition. Hint: use &&. Inside this if statement (check date-difference)
は、ここで私が持っているものだ。すべてのヘルプは大歓迎されます
An exception of type 'System.FormatException' occurred in mscorlib.dll but was not handled in user code. Additional information: String was not recognized as a valid DateTime.
:
DateTime startDate = DateTime.Parse(Request["txtStartDate"]);
DateTime endDate = DateTime.Parse(Request["txtEndDate"]);
if (DateTime.Compare(startDate, endDate) > 0)
{
txtStartDate.BackColor = System.Drawing.Color.Yellow;
txtEndDate.BackColor = System.Drawing.Color.Yellow;
lblError.Text += "The end date must be a later date than the start date.";
//The Msg text will be displayed in lblError.Text after all the error messages are concatenated
bIsFormValid = false;
//Boolean value - test each textbox to see if the data entered is valid, if not set validState=false.
//If after testing each validation rule, the validatedState value is true, then submit to frmPersonnelVerified.aspx, if not, then display error message
}
else
{
txtStartDate.BackColor = System.Drawing.Color.White;
txtEndDate.BackColor = System.Drawing.Color.White;
}
// Redirect the User to frmStudentConfirmed.aspx
if (bIsFormValid)
{
Response.Redirect("frmPersonnelVerified.aspx");
}
else
{
Session.Clear();
}
は、私は次のエラーを取得しています。 ミゲル
が鳴ります。 'Request [" txtStartDate "]'と 'Request [" txtEndDate "]'の文字列をチェックして、それらを解析してDateTimeオブジェクトに変換する方法を知っているかどうか確認してください。 – yeedle
はこれ以上明らかにすることはできません - > "追加情報:文字列が有効なDateTimeとして認識されませんでした。"しかし、ええ@yeedleは、あなたが目を向けなければならないことについて言及しています。 –
textStartDateとtxtEndDateに渡す値を質問に追加する必要があります。その後、私はdatetimeを正しく解析する方法を教えてくれるはずです。 – vgwizardx