如何通过日历asp.net控件选择并插入已设定的日期?

2026-04-30 12:4115阅读0评论SEO基础
  • 内容介绍
  • 文章标签
  • 相关推荐

本文共计359个文字,预计阅读时间需要2分钟。

如何通过日历asp.net控件选择并插入已设定的日期?

我需要在文本框中插入日期,然后在日历中选择相应日期。我正在使用Microsoft Visual Studio Express 2012中的日历控件,通过选择日历上的日期来将日期插入文本框。

我需要知道是否可以在文本框中插入日期,然后在日历中选择该日期.我正在使用Microsoft visual studio express 2012中的日历用于Web.

下面是通过选择日历上的日期将日期插入文本框的代码. (但我想做相反的事)

Default.aspx的

如何通过日历asp.net控件选择并插入已设定的日期?

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="www.w3.org/1999/xhtml"> <head id="Head1" runat="server"> <title></title> </head> <body> <form id="form1" runat="server"> <div> <asp:Calendar ID="Calendar1" runat="server" Visible="False" OnSelectionChanged="Calendar1_SelectionChanged"></asp:Calendar> </div> <asp:TextBox ID="TextBox1" runat="server"></asp:TextBox> <asp:LinkButton ID="LinkButton1" runat="server" onclick="LinkButton1_Click">PickDate...</asp:LinkButton> </form>

Default.aspx.cs

using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.Web.UI; using System.Web.UI.WebControls; public partial class _Default : System.Web.UI.Page { protected void Page_Load(object sender, EventArgs e) { } protected void LinkButton1_Click(object sender, EventArgs e) { Calendar1.Visible = true; } protected void Calendar1_SelectionChanged(object sender, EventArgs e) { TextBox1.Text = Calendar1.SelectedDate.ToLongDateString(); Calendar1.Visible = false; } }

谢谢

怎么样

protected void TextBox1_TextChanged(object sender, EventArgs e) { Calendar1.SelectedDate = Convert.ToDateTime(TextBox1.Text); }

本文共计359个文字,预计阅读时间需要2分钟。

如何通过日历asp.net控件选择并插入已设定的日期?

我需要在文本框中插入日期,然后在日历中选择相应日期。我正在使用Microsoft Visual Studio Express 2012中的日历控件,通过选择日历上的日期来将日期插入文本框。

我需要知道是否可以在文本框中插入日期,然后在日历中选择该日期.我正在使用Microsoft visual studio express 2012中的日历用于Web.

下面是通过选择日历上的日期将日期插入文本框的代码. (但我想做相反的事)

Default.aspx的

如何通过日历asp.net控件选择并插入已设定的日期?

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="www.w3.org/1999/xhtml"> <head id="Head1" runat="server"> <title></title> </head> <body> <form id="form1" runat="server"> <div> <asp:Calendar ID="Calendar1" runat="server" Visible="False" OnSelectionChanged="Calendar1_SelectionChanged"></asp:Calendar> </div> <asp:TextBox ID="TextBox1" runat="server"></asp:TextBox> <asp:LinkButton ID="LinkButton1" runat="server" onclick="LinkButton1_Click">PickDate...</asp:LinkButton> </form>

Default.aspx.cs

using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.Web.UI; using System.Web.UI.WebControls; public partial class _Default : System.Web.UI.Page { protected void Page_Load(object sender, EventArgs e) { } protected void LinkButton1_Click(object sender, EventArgs e) { Calendar1.Visible = true; } protected void Calendar1_SelectionChanged(object sender, EventArgs e) { TextBox1.Text = Calendar1.SelectedDate.ToLongDateString(); Calendar1.Visible = false; } }

谢谢

怎么样

protected void TextBox1_TextChanged(object sender, EventArgs e) { Calendar1.SelectedDate = Convert.ToDateTime(TextBox1.Text); }