Asp.net“控件”“Calendar”的用法?
答非我问,我会检举!!!答非我问,我会检举!!!请不要怪我说话不礼貌,有的人我问编程给我留诗歌!开发工具:VS005.net,语言:C#1、开始我要文本框里显示当时日期!...
答非我问,我会检举!!!答非我问,我会检举!!!请不要怪我说话不礼貌,有的人我问编程给我留诗歌!开发工具:VS005.net , 语言:C#1、开始我要文本框里显示当时日期!2、我要选定日期后,把日期附给文本框!3、然后它不可见。4、我要把文本框的值存入数据库,把字符串型转为DateTime型。谢谢!
展开
1个回答
2012-02-13
展开全部
【DEMO】
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>无标题页</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
<asp:Calendar ID="Calendar1" runat="server" OnSelectionChanged="Calendar1_SelectionChanged">
</asp:Calendar>
</div>
</form>
</body>
</html>
using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
public partial class _Default : System.Web.UI.Page
{
protected void Calendar1_SelectionChanged(object sender, EventArgs e)
{
TextBox1.Text = Calendar1.SelectedDate.ToString ("yyyy-MM-dd"); //显示选中的时间
Calendar1.Visible = false; //隐藏Calendar控件
}
protected void Page_Load(object sender, EventArgs e)
{
TextBox1.Text = DateTime.Now.ToString("yyyy-MM-dd"); //显示当前时间
}
}
【附】把字符串型转为DateTime用“DateTime.Parse”方法就可以了
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>无标题页</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
<asp:Calendar ID="Calendar1" runat="server" OnSelectionChanged="Calendar1_SelectionChanged">
</asp:Calendar>
</div>
</form>
</body>
</html>
using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
public partial class _Default : System.Web.UI.Page
{
protected void Calendar1_SelectionChanged(object sender, EventArgs e)
{
TextBox1.Text = Calendar1.SelectedDate.ToString ("yyyy-MM-dd"); //显示选中的时间
Calendar1.Visible = false; //隐藏Calendar控件
}
protected void Page_Load(object sender, EventArgs e)
{
TextBox1.Text = DateTime.Now.ToString("yyyy-MM-dd"); //显示当前时间
}
}
【附】把字符串型转为DateTime用“DateTime.Parse”方法就可以了
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询