In order to improve the refresh efficiency of tree control, local refresh technique is used.
The. aspx code is as follows:
<%@ page language= "C #" autoeventwireup= "true" codefile= "China urban District aspx.cs" inherits= "China urban District"%>
<! DOCTYPE HTML PUBLIC "-//W3C//DTD XHTML 1.0 transitional//en" "Http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd ">
<title></title>
<style type= "Text/css" >
. fl{Float:left;}
</style>
<body>
<form id= "Form1" runat= "Server" >
<div>
<div class= "FL" runat= "Server" >
<p><%=datetime.now.tostring ()%></p>
<asp:treeview id= "Tv_china" runat= "Server"
Onselectednodechanged= "tv_china_selectednodechanged" expanddepth= "0" >
</asp:TreeView>
<asp:scriptmanager
Id= "ScriptManager1" runat= "Server" >
</asp:ScriptManager>
</div>
<asp:updatepanel id= "UpdatePanel1" runat= "Server" >
<ContentTemplate>
<p><%=datetime.now.tostring ()%></p>
Text:<asp:label id= "Label1" runat= "Server" text= "" ></asp:Label>
Value:<asp:label id= "Label2" runat= "Server" text= "" ></asp:Label>
Valuepath:<asp:label id= "Label3" runat= "Server" text= "" ></asp:Label>
</ContentTemplate>
<triggers >
<asp:asyncpostbacktrigger controlid= "Tv_china"/>
</Triggers>
</asp:UpdatePanel>
</div>
</form>
</body>
Observe the change of time within two controls to see the effect of local refresh.
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;using system.data.oledb;public partial class China City: system.web.ui.page{string str_cnn = "Pr ovider=microsoft.jet.oledb.4.0; Data source= "; String str_sourcefile = "~/data/china.mdb"; OleDbConnection CNN; OleDbCommand cmd; OleDbDataReader Datar; String Str_sql; protected void Page_Load (object sender, EventArgs e) {if (! IsPostBack) {maketree (); }} protected void Maketree () {TreeNode _tnode, _parentnode; String str_conn = str_cnn + MapPath (str_sourcefile); CNN = new OleDbConnection (Str_conn); Cnn. Open (); Build a level (province) Str_sql = "Select P_id,p_name from T_province"; cmd = new OleDbCommand (Str_sql, CNN); Datar = cmd. ExecuteReader (); while (Datar. Read ()) {_tnode = new TreeNode (); _tnode. Text = Datar["P_name"]. ToString (); _tnode. Value= "P_" +datar["p_id"]. ToString (); Tv_china. Nodes.Add (_tnode); }//Build Level Two (city) str_sql = "Select C_id,c_name,c_pid from T_city"; cmd = new OleDbCommand (Str_sql, CNN); Datar = cmd. ExecuteReader (); while (Datar. Read ()) {_parentnode = Tv_china. FindNode ("P_" + datar["C_pid"]. ToString ()); _tnode = new TreeNode (); _tnode. Text = datar["C_name"]. ToString (); _tnode. Value = "C_" + datar["c_id"]. ToString (); _parentnode.childnodes.add (_tnode); }//Build Level Three (zone) str_sql = "Select T_city.c_pid, t_city.c_id, t_district.d_id, t_district.d_name from T_district INNER JOIN t_city on t_district.d_cid = t_city.c_id "; cmd = new OleDbCommand (Str_sql, CNN); Datar = cmd. ExecuteReader (); while (Datar. Read ()) {_parentnode = Tv_china. FindNode ("P_" + datar["C_pid"]. ToString () + "/c_" + datar["c_id"]. ToString ()); _tnode = new TreeNode (); _tnode. Text = datar["D_name"]. ToString (); _tnode. Value = "D_" + datar["d_id"]. ToString (); _parentnode.childnodes.add (_tnode); } CNN. Close (); } protected void Tv_china_selectednodechanged (object sender, EventArgs e) {TreeNode _tnode; _tnode = Tv_china. SelectedNode; Label1.Text = _tnode. Text; Label2.Text = _tnode. Value; Label3.text = _tnode. Valuepath; }}
The effect is as follows:
The UpdatePanel Control for ASP.