| <%@ Page language="c#" Codebehind="ParentPage.aspx.cs" AutoEventWireup="false" Inherits="PopupWithDiv.ParentPage" %> <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" > <HTML> <HEAD> <title>Parent Page</title> <LINK href="main.CSS" type="text/css" rel="stylesheet"> ?。約cript src="jspopup.js" type="text/Javascript"></script> ?。約cript language="javascript"> <!-- // PRevent users from typing any text // into the Textbox function ProtectBox(e) {return false; } //--> ?。?script> </HEAD> <body> ?。糵orm id="Form1" method="post" runat="server"> <!-- Header Section --> ?。糳iv id="header"> ?。紁>Popup Window with DIV Layer</p> </div> ?。?-- Body Section --> <div id="content"> ?。紅able border="0" cellpadding="0" cellspacing="0"> <tr valign="top"> ?。紅d><label for="txtCountry">Country :</label></td> ?。紅d><asp:TextBox id="txtCountry" runat="server" OnKeyDown="return ProtectBox(event);" OnClick="PopupArea(event, 'divCountry')"></asp:TextBox></td> ?。紅d width="50"></td> ?。紅d><label for="txtCity">City :</label></td> ?。紅d><asp:TextBox id="txtCity" runat="server" OnKeyDown="return ProtectBox(event);" OnClick="PopupArea(event, 'divCity')"></asp:TextBox></td> ?。?tr> </table> ?。?div> ?。?-- Country --%> <div class="popupWindow" id="divCountry"> <table cellSpacing="0" cellPadding="0" width="100%" bgColor="#2557ad" border="0"> ?。紅r> ?。紅d align="right"><span style="CURSOR: hand" onclick="jsAreaClose('divCountry')"><img alt="Hide Popup" src="close.gif" border="0"></span></td> ?。?tr> ?。紅r> ?。紅d> <asp:ListBox id="lstCountry" runat="server" AutoPostBack="True" width="100%" rows="10"></asp:ListBox></td> ?。?tr> ?。?table> ?。?div> ?。?-- City --%> <div class="popupWindow" id="divCity"> <table cellSpacing="0" cellPadding="0" width="100%" bgColor="#2557ad" border="0"> ?。紅r> ?。紅d align="right"><span style="CURSOR: hand" onclick="jsAreaClose('divCity')"><img alt="Hide Popup" src="close.gif" border="0"></span></td> </tr> ?。紅r> ?。紅d> <asp:ListBox id="lsCity" runat="server" AutoPostBack="True" width="100%" rows="10"></asp:ListBox> ?。?td> ?。?tr> </table> </div> </form> </body> </HTML> |
![]() |
當單擊Textbox內部,windows將彈出窗體而不會引起頁面數(shù)據(jù)回發(fā)現(xiàn)在該到填充其中數(shù)據(jù)的時候了
Page COde-behind
在頁面后臺,我們準備從一個xml文檔加載list“國家”所需要的數(shù)據(jù),同時顯示國家的名稱,下面列出了這個功能的代碼:
Listing 2: Populate Country ListBox
| // Load data into Country List box if (!Page.IsPostBack) { // Load data from XML into a DataSet DataSet ds = new DataSet(); ds.ReadXml(Server.MapPath("countries.xml")); this.lstCountry.DataSource = ds.Tables[0].DefaultView; this.lstCountry.DataTextField = "name"; this.lstCountry.DataBind(); } |
![]() |
| private void lstCountry_SelectedIndexChanged(object sender, EventArgs e) { // Set the value in the textbox this.txtCountry.Text = this.lstCountry.SelectedValue; // Load and Filter the lstCity DataSet ds = new DataSet(); ds.ReadXml(Server.MapPath("cities.xml")); DataView dv = ds.Tables[0].DefaultView; dv.RowFilter = "country = '" + this.lstCountry.SelectedValue + "'"; // Bind lstCity this.lstCity.DataSource = dv; this.lstCity.DataTextField = "name"; this.lstCity.DataBind(); } |
![]() |
新聞熱點
疑難解答