62,046
社区成员
发帖
与我相关
我的任务
分享
<%@ Page Language="C#" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<script runat="server">
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
this.Calendar1.Style["display"] = "none";
this.TextBox1.Attributes["ondblclick"] = "var obj=" + this.Calendar1.ClientID + ";obj.style.display=obj.style.display=='none'?'inline':'none'";
}
protected void Calendar1_SelectionChanged(object sender, EventArgs e)
{
this.TextBox1.Text = this.Calendar1.SelectedDate.ToString("yyyy-M-d");
}
</script>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
简单示例Calendar用法。实际使用时应该添加Calendar的更多控制事件,并且放入UpdatePanel中。
</head>
<body>
<form id="form1" runat="server">
<div>
<table>
<tr>
<td>
请输入日期:
</td>
<td width="200px">
<table border="0">
<tr>
<td>
<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
</td>
</tr>
<tr>
<td style="position: absolute">
<asp:Calendar ID="Calendar1" runat="server" OnSelectionChanged="Calendar1_SelectionChanged">
</asp:Calendar>
</td>
</tr>
</table>
</td>
</tr>
</table>
</div>
</form>
</body>
</html>