日期:2014-05-17 浏览次数:20452 次
<%@ Page Language="C#" %> <script runat="server"> protected void Page_Load(object sender, EventArgs e) { if (!IsPostBack) { this.Calendar1.Style["position"] = "absolute"; this.TextBox1.DataBind(); } } protected void DropDownList1_SelectedIndexChanged(object sender, EventArgs e) { this.DropDownList2.Items.Clear(); switch (this.DropDownList1.SelectedValue) { case "北京": this.DropDownList2.Items.Add("天安门广场"); this.DropDownList2.Items.Add("颐和园"); this.DropDownList2.Items.Add("雍和宫"); this.DropDownList2.Items.Add("红螺寺"); break; case "上海": this.DropDownList2.Items.Add("崇明岛"); this.DropDownList2.Items.Add("外滩"); this.DropDownList2.Items.Add("万佛阁"); break; case "香港": this.DropDownList2.Items.Add("海洋公园"); this.DropDownList2.Items.Add("半岛酒店"); break; } } protected void DropDownList2_SelectedIndexChanged(object sender, EventArgs e) { ShowResult(); } protected void Button1_Click(object sender, EventArgs e) { if (this.Calendar1.Visible) SetupTheDate(); else { try { this.Calendar1.SelectedDate = DateTime.Parse(this.TextBox1.Text); this.Calendar1.VisibleDate = this.Calendar1.SelectedDate; } catch { } this.Calendar1.Visible = true; } } protected void Calendar1_SelectionChanged(object sender, EventArgs e) { SetupTheDate(); } private void SetupTheDate() { this.TextBox1.Text = this.Calendar1.SelectedDate.ToShortDateString(); this.Calendar1.Visible = false; ShowResult(); } void ShowResult() { this.Label1.Text = "您选择" + this.TextBox1.Text + "去" + this.DropDownList2.SelectedValue; UpdatePanel3.Update(); } </script> <!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 id="Head1" runat="server"> <title>演示使用基本的asp.net ajax功能</title> </head> <body> <form id="form1" runat="server"> <asp:ScriptManager ID="ScriptManager1" runat="server" /> <asp:UpdatePanel ID="UpdatePanel1" runat="server" UpdateMode="Conditional"> <ContentTemplate> <asp:DropDownList ID="DropDownList1" runat="server" AutoPostBack="True" OnSelectedIndexChanged="DropDownList1_SelectedIndexChanged"> <asp:ListItem>--请选择--</asp:ListItem> <asp:ListItem>北京</asp:ListItem> <asp:ListItem>上海</asp:ListItem> <asp:ListItem>香港</asp:ListItem> </asp:DropDownList> <asp:DropDownList ID="DropDownList2" runat="server" AutoPostBack="True" OnSelectedIndexCh