我想將日期添加到當前日期例如我想輸入數字的日期並且比我選擇我想要在當前日期中添加的日期指天,周,月,但是當我選擇天或數週或數月就說明天,但不能在其中添加在當前日期 任何一個可以幫助我PLZ如何使用asp.net添加當前日期的天數
protected void TextBoxPredictDays_TextChanged(object sender, EventArgs e)
{
string selectPredictDays = DropDownList1.SelectedItem.Value;
String Days1;
int Result;
Days1 = TextBoxPredictedClosing.ToString();
if (selectPredictDays == "Days")
{
Result = Convert.ToInt32(TextBoxPredictDays.Text) * 1;
TextBoxPredictedClosing.Text = Result.ToString();
}
else if (selectPredictDays == "Weeks")
{
Result = Convert.ToInt32(TextBoxPredictDays.Text) * 7;
TextBoxPredictedClosing.Text = Result.ToString();
}
else if (selectPredictDays == "Months")
{
Result = Convert.ToInt32(TextBoxPredictDays.Text) * 30;
TextBoxPredictedClosing.Text = Result.ToString();
}
}
這是我設計的代碼
<asp:TextBox ID="TextBoxPredictDays" runat="server"
ontextchanged="TextBoxPredictDays_TextChanged" Width="101px" Height="14px" ></asp:TextBox>
<asp:DropDownList ID="DropDownList1" runat="server"
onselectedindexchanged="DropDownList1_SelectedIndexChanged">
<asp:ListItem>Days</asp:ListItem>
<asp:ListItem>Weeks</asp:ListItem>
<asp:ListItem>Months</asp:ListItem>
</asp:DropDownList>
你要求今天的日期時間= DateTime.Now; DateTime answer = today.AddDays(36);請參閱https://msdn.microsoft.com/zh-CN/library/system.datetime.adddays(v=vs.110).aspx – Anil