1

我已经为此工作了很长时间。我的代码将显示我试图解决问题的所有不同方式和事情,但没有运气......到目前为止。我需要做的是:

  1. 为表单的 Load 事件启动事件处理程序。然后添加代码以在没有回发表单的情况下以上面显示的格式显示当前日期。
  2. 将日历控件添加到下一段,并将其 Visible 属性设置为 False,以便在第一次显示表单时将其隐藏。
  3. 为图像按钮的 Click 事件编写事件处理程序。这将隐藏图像按钮并显示日历控件。
  4. 为日历控件的 SelectionChanged 事件编写事件处理程序。这应该获取选定的日期并将其显示在带有今天日期的文本框中,并且还应该隐藏日历控件并显示图像按钮。

我希望有人可以帮助我解决我做错了什么并帮助我找到正确的解决方案。到目前为止,对结果并不满意。

我的代码隐藏:

Partial Class Request
    Inherits Page

Dim ImageButton1 As ImageButton1

Protected Sub Calendar_SelectionChanged(object sender, EventArgs e)
    Label.Text = "Current date: " + System.DateTime.Now.ToLongDateString()
    Label.Text = "Selected date: " + Calendar.SelectedDate.ToLongDateString()

    Dim label1 = System.DateTime.Now
    Dim label2 = SelectedDate
    Dim ImageButton1 = ImageButton1
End Sub

protected void Calendar_SelectionChanged(object sender, EventArgs e)
{
    lblday.Text = Calendar1.TodaysDate.ToShortDateString();
    lblbday.Text = Calendar1.SelectedDate.ToShortDateString();
}

' Display using current (en-us) culture's short date format 
Dim ddlDate As Date = #3/15/2008#

Protected Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs) Handles   Me.Load
   Calendar.SelectedDate = DateTime.Now;
   Label.Text = "Today's date and time is :" + Calendar.SelectedDate;
   Calendar.SelectedDate = DateTime.Today
End Sub

Protected Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs) Handles Me.Load
    If Not IsPostBack Then
        Me.clnArrival = thisDate.ToString
    End If
End Sub

Sub Submit(s As Object, e As EventArgs)
    TextBox1.Text = "The date and time is " & Now()
End Sub

Protected Sub ddlDay_SelectedIndexChanged(ByVal sender As Object, ByVal e As   EventArgs) Handles ddlDay.SelectedIndexChanged
    clnArrival.Visible = False
    Dim day As String = ddlDay.SelectedItem.Text(ddlDay.SelectedValue)
End Sub

Protected Sub ddlMonth_SelectedIndexChanged(ByVal sender As Object, ByVal e As EventArgs) Handles ddlMonth.SelectedIndexChanged
    Dim month As String = ddlMonth.SelectedItem.Text(ddlMonth.SelectedValue)
End Sub

 Protected Sub clnArrival_SelectionChanged(ByVal sender As Object, ByVal e As EventArgs) Handles clnArrival.SelectionChanged
    ddlMonth_SelectedValue = clnArrival.SelectedDate.Month.ToString
    ddlDay_SelectedValue = clnArrival.SelectedDate.Day.ToString
    clnArrival.Visible = True
End Sub
End Class

我的标记:

<%@ Page Language="VB" AutoEventWireup="false" CodeFile="Request.aspx.vb" Inherits="Request" %>

<!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>Chapter 6: Reservations</title>
    <link href="Styles/Main.css" rel="stylesheet" type="text/css" />
    <link href="Styles/Request.css" rel="stylesheet" type="text/css" />

    <script language="VB" runat="server">
        Sub Page_Load()
            Response.Write("Today is: ")
        End Sub
    </script>    
</head>
<body>
<form id="form1" runat="server">
    <div id="page">
        <h1>Royal Inn and Suites</h1>
        <h2>Where you&rsquo;re always treated like royalty</h2>
        <p id="arrival_date">
            Arrival date:&nbsp;

        <asp:Calendar ID = "Calendar" runat = "server" SelectionMode="DayWeekMonth" OnSelectionChanged="Calendar_SelectionChanged" SelectedDate="1/1/0001" VisibleDate="1/1/0001">
            <asp:ImageButton ID="ImageButton1" runat="server" AlternateText="Click to show calendar" ImageUrl="C:\aspnet4_vb\Jeanne Tatro Webs 424 - HW 6 - Ch06Reservation\Images\Calendar.bmp" />
        </asp:Calendar>
        </p>
        <p class="clear">
            Number of nights:&nbsp; 
        </p>
        <p>
            Number of adults:&nbsp;
            Children:&nbsp;
        </p>
        <h3>Preferences</h3>
        <p>
            Room type:&nbsp;
        </p>
        <p>
            Bed type:&nbsp;
        </p>
        <p id="requests">Special requests:</p>
        <h3 class="clear">Contact information</h3>
        <p class="contact">Name:</p>
        <p class="contact">Email:</p>
        <p id="buttons"></p>
        <p id="message"></p>
    </div>
</form>
</body>
</html>
4

0 回答 0