The. Master code is as follows:
<%@ Master language= "VB" codefile= "0_mst_aspnet12.master.vb" inherits= "_0_mst_aspnet12"%><! DOCTYPE HTML PUBLIC "-//W3C//DTD XHTML 1.0 transitional//en" "Http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd ">
The. aspx code is as follows:<%@ page title= "" Language= "C #" masterpagefile= "~/0_mst_aspnet12.master" autoeventwireup= "true" CodeFile= "S4_ UpdatePanel_ddls.aspx.cs "inherits=" Sample_code_s4_updatepanel_ddls "%><asp:content id=" Content1 " Contentplaceholderid= "Head" runat= "Server" ></asp:content><asp:content id= "Content2" Contentplaceholderid= "Cph_memo" runat= "Server" > <strong> cascading Queries dropdownlist:</strong> <ul> <li>ddl_p[Province], content will not change, placed outside of UpdatePanel </li> <li> settings triggers-ddl_p</li> <li>dd l_c[City] After data binding, the Ddl_d data is affected again, so after the binding is complete, you need to force the ddl_d to bind the data again </li> <li> to grasp the location of data binding in the page life cycle </li> </ul> ; </asp:content><asp:content id= "Content3" contentplaceholderid= "Cph_main" runat= "Server" > <p class = " Showtime "> Page Time: <%=datetime.now.tofiletime ()%></p> Please select a region: <asp:dropdownlist id=" ddl_p "runat=" Ser Ver "datasourceid=" ads_p "datatextfield=" P_name "datavaluefield=" p_id "Autopostback= "True" > </asp:DropDownList> <asp:accessdatasource id= "ads_p" runat= "Server" datafile= "~/data /china.mdb "selectcommand=" select * from [t_province] "/> <asp:scriptmanager id=" ScriptManager1 "runat=" se RVer "> </asp:ScriptManager> <asp:updatepanel id=" Upnl_ddls "runat=" Server "rendermode=" Inline "U Pdatemode= "Conditional" > <%--rendermode= "Inline" is displayed as a stream (row display)--%> <ContentTemplate> <asp:dropdownlist id= "Ddl_c" runat= "Server" datasourceid= "Ads_c" datatextfield= "C_name" Datavalu Efield= "c_id" autopostback= "True" ondatabound= "Load_d" ><%--ondatabound= "load_d" Force binding--%> </asp:Dro pdownlist> <asp:accessdatasource id= "Ads_c" runat= "Server" datafile= "~/data/china.mdb" Se Lectcommand= "SELECT [C_name], [c_id] from [t_city] WHERE ([c_pid] =?)" > <SelectParameters> <asp:contRolparameter controlid= "ddl_p" name= "C_pid" propertyname= "SelectedValue" type= "Int32"/> </SelectParameters> </asp:AccessDataSource> <asp:dropdownlist id= "Ddl_d" R unat= "Server" datasourceid= "Ads_d" ondatabound= "Checkitems" datatextfield= "D_name" datavaluefield= "d_id" &G T </asp:DropDownList> <asp:accessdatasource id= "ads_d" runat= "Server" datafile= "~/data/china.mdb" Selectcommand= "SELECT [d_id], [d_name] from [t_district] WHERE ([d_cid] =?)" > <SelectParameters> <asp:controlparameter controlid= "Ddl_c" name= "D_cid" Propertyname= "SelectedValue" type= "Int32"/> </SelectParameters> </asp:AccessDataSource> <p class = "Showtime" >updatepanel Time: <%=datetime.now.tofiletime ()%>&L T;/p> </ContentTemplate> <Triggers> <asp:asyncpostbacktrigger ControlID = "ddl_p"/> </Triggers> </asp: updatepanel> </asp:content><asp:content id= "Content4" contentplaceholderid= "Cph_output" Runat= "Server" > <asp:button id= "Button1" runat= "server" text= "read select" onclick= "Button1_Click"/> <asp:label id= "Lbl_resu LT "runat=" server "/></asp:content>
Note the point:<span style= "Background-color:rgb (204, 0, 0); > rendermode= "Inline" </span>
<span style= "Background-color:rgb (204, 0, 0); > ondatabound= "Load_d" </span>
The. Aspx.cs code is as follows:Using system;using system.collections.generic;using system.linq;using system.web;using System.Web.UI;using System.web.ui.webcontrols;public partial class sample_code_s4_updatepanel_ddls:system.web.ui.page{ protected void Page_Load (object sender, EventArgs e) { } //Second DDL, after data binding is complete, requires a third DDL to be re-bound protected void Load _d (object sender, EventArgs e) { ddl_d.databind (); } The last DDL, if the content is empty, does not display protected void Checkitems (object s, EventArgs e) { if (Ddl_d.Items.Count = = 0) {Ddl_d.styl e["display"] = "none"; } else {Ddl_d.Style.Remove ("display");} } Read the selected button protected void Button1_Click (object sender, EventArgs e) { string _s = "you selected:" + ddl_p. Selecteditem.text + "/" + Ddl_c.SelectedItem.Text + "/" + Ddl_d.SelectedItem.Text + ". "; Lbl_result. Text = _s; }}
The effect is as follows:
UpdatePanel controls implement no refresh Cascade