1

我正在使用带有 ASP.NET 的日历控件来填充带有所选日期的文本框。选择日期时,应显示在标签中,但标签不显示所选日期。请帮忙。谢谢你。

这是我将日期放入标签的代码:

<%@ Page Title="" Language="C#" MasterPageFile="~/Views/Shared/Site.Master" Inherits="System.Web.Mvc.ViewPage<dynamic>" %>

<script runat="server">

    protected void Calendar1_SelectionChanged(object sender, EventArgs e)
    {
        Label1.Text = Calendar1.SelectedDate.ToString();
    }
</script>
<asp:Content ID="Content1" ContentPlaceHolderID="TitleContent" runat="server">
    MakeAppointment
</asp:Content>

<asp:Content ID="Content2" ContentPlaceHolderID="MainContent" runat="server">

    <form id="form1" runat="server" style="height: 388px">

    <h2>MakeAppointment<asp:Calendar ID="Calendar1" runat="server" 
            onselectionchanged="Calendar1_SelectionChanged"></asp:Calendar>
    </h2>

    <asp:Label ID="Label1" runat="server" Text="Label"></asp:Label>
    </form>

</asp:Content>
4

1 回答 1

0

尝试指定language="c#".

<script language="c#" runat="server">
protected void Calendar1_SelectionChanged(object sender, EventArgs e)
{
  Label1.Text = Calendar1.SelectedDate.ToString();
}
</script>

只是一个建议,你应该去jQuery UI Datapicker

演示:数据选择器

代码示例:

<!doctype html>

<html lang="en">
<head>
    <meta charset="utf-8" />
    <title>jQuery UI Datepicker - Default functionality</title>
    <link rel="stylesheet" href="http://code.jquery.com/ui/1.9.1/themes/base/jquery-ui.css" />
    <script src="http://code.jquery.com/jquery-1.8.2.js"></script>
    <script src="http://code.jquery.com/ui/1.9.1/jquery-ui.js"></script>
    <link rel="stylesheet" href="/resources/demos/style.css" />
    <script>
    $(function() {
        $( "#datepicker" ).datepicker();
    });
    </script>
</head>
<body>

<p>Date: <input type="text" id="datepicker" /></p>


</body>
</html>
于 2012-11-12T09:38:50.890 回答