省市联动菜单(ASP.NET + XML)

using  System;
省市联动菜单(ASP.NET + XML)
using  System.Collections;
省市联动菜单(ASP.NET + XML)
using  System.ComponentModel;
省市联动菜单(ASP.NET + XML)
using  System.Data;
省市联动菜单(ASP.NET + XML)
using  System.Drawing;
省市联动菜单(ASP.NET + XML)
using  System.Web;
省市联动菜单(ASP.NET + XML)
using  System.Web.SessionState;
省市联动菜单(ASP.NET + XML)
using  System.Web.UI;
省市联动菜单(ASP.NET + XML)
using  System.Web.UI.WebControls;
省市联动菜单(ASP.NET + XML)
using  System.Web.UI.HtmlControls;
省市联动菜单(ASP.NET + XML)
using  System.Xml;
省市联动菜单(ASP.NET + XML)
省市联动菜单(ASP.NET + XML)
namespace  WebApplication2
省市联动菜单(ASP.NET + XML)
{
省市联动菜单(ASP.NET + XML)    
/// <summary>
省市联动菜单(ASP.NET + XML)    
/// WebForm1 的摘要说明。
省市联动菜单(ASP.NET + XML)    
/// </summary>

省市联动菜单(ASP.NET + XML)    public class WebForm1 : System.Web.UI.Page
省市联动菜单(ASP.NET + XML)    
{
省市联动菜单(ASP.NET + XML)        
protected System.Web.UI.WebControls.DropDownList DropDownListProvince;
省市联动菜单(ASP.NET + XML)        
protected System.Web.UI.WebControls.DropDownList DropDownListCity;
省市联动菜单(ASP.NET + XML)        
protected System.Web.UI.WebControls.Label LabelMessage;
省市联动菜单(ASP.NET + XML)
省市联动菜单(ASP.NET + XML)        
public string City = "广州";
省市联动菜单(ASP.NET + XML)        
省市联动菜单(ASP.NET + XML)    
省市联动菜单(ASP.NET + XML)        
private void Page_Load(object sender, System.EventArgs e)
省市联动菜单(ASP.NET + XML)        
{
省市联动菜单(ASP.NET + XML)            
// 在此处放置用户代码以初始化页面
省市联动菜单(ASP.NET + XML)
            string CurrentPath = this.Server.MapPath(".");
省市联动菜单(ASP.NET + XML)
省市联动菜单(ASP.NET + XML)            
if (!Page.IsPostBack)
省市联动菜单(ASP.NET + XML)            
{
省市联动菜单(ASP.NET + XML)                
if(System.IO.File.Exists(CurrentPath + "\\Province.xml"))
省市联动菜单(ASP.NET + XML)                
{
省市联动菜单(ASP.NET + XML)                    
this.DropDownListProvince.Items.Clear();
省市联动菜单(ASP.NET + XML)
省市联动菜单(ASP.NET + XML)                    System.Xml.XmlDocument doc 
= new System.Xml.XmlDocument();
省市联动菜单(ASP.NET + XML)                    doc.Load(CurrentPath 
+ "\\Province.xml");
省市联动菜单(ASP.NET + XML)
省市联动菜单(ASP.NET + XML)                    XmlNodeList nodes 
= doc.DocumentElement.ChildNodes;
省市联动菜单(ASP.NET + XML)
省市联动菜单(ASP.NET + XML)                    XmlNode node1 
= doc.DocumentElement.SelectSingleNode(@"Province/City[@Name='" + this.City + "']");
省市联动菜单(ASP.NET + XML)
省市联动菜单(ASP.NET + XML)                    
foreach(XmlNode node in nodes)
省市联动菜单(ASP.NET + XML)                    
{
省市联动菜单(ASP.NET + XML)                        
this.DropDownListProvince.Items.Add(node.Attributes["Name"].Value);
省市联动菜单(ASP.NET + XML)                        
int n = this.DropDownListProvince.Items.Count - 1;
省市联动菜单(ASP.NET + XML)                    
省市联动菜单(ASP.NET + XML)                        
if(node1 != null && node == node1.ParentNode)
省市联动菜单(ASP.NET + XML)                            
this.DropDownListProvince.SelectedIndex = n;
省市联动菜单(ASP.NET + XML)                    }

省市联动菜单(ASP.NET + XML)                    DropDownListProvince_SelectedIndexChanged(sender,e);
省市联动菜单(ASP.NET + XML)                }

省市联动菜单(ASP.NET + XML)                
else
省市联动菜单(ASP.NET + XML)                
{
省市联动菜单(ASP.NET + XML)                    
this.LabelMessage.Text = "地市信息文件丢失!";
省市联动菜单(ASP.NET + XML)                }

省市联动菜单(ASP.NET + XML)            }

省市联动菜单(ASP.NET + XML)        }

省市联动菜单(ASP.NET + XML)
省市联动菜单(ASP.NET + XML)        
#region Web 窗体设计器生成的代码
省市联动菜单(ASP.NET + XML)        
override protected void OnInit(EventArgs e)
省市联动菜单(ASP.NET + XML)        
{
省市联动菜单(ASP.NET + XML)            
//
省市联动菜单(ASP.NET + XML)            
// CODEGEN: 该调用是 ASP.NET Web 窗体设计器所必需的。
省市联动菜单(ASP.NET + XML)            
//
省市联动菜单(ASP.NET + XML)
            InitializeComponent();
省市联动菜单(ASP.NET + XML)            
base.OnInit(e);
省市联动菜单(ASP.NET + XML)        }

省市联动菜单(ASP.NET + XML)        
省市联动菜单(ASP.NET + XML)        
/// <summary>
省市联动菜单(ASP.NET + XML)        
/// 设计器支持所需的方法 - 不要使用代码编辑器修改
省市联动菜单(ASP.NET + XML)        
/// 此方法的内容。
省市联动菜单(ASP.NET + XML)        
/// </summary>

省市联动菜单(ASP.NET + XML)        private void InitializeComponent()
省市联动菜单(ASP.NET + XML)        
{    
省市联动菜单(ASP.NET + XML)            
this.DropDownListProvince.SelectedIndexChanged += new System.EventHandler(this.DropDownListProvince_SelectedIndexChanged);
省市联动菜单(ASP.NET + XML)            
this.Load += new System.EventHandler(this.Page_Load);
省市联动菜单(ASP.NET + XML)
省市联动菜单(ASP.NET + XML)        }

省市联动菜单(ASP.NET + XML)        
#endregion

省市联动菜单(ASP.NET + XML)
省市联动菜单(ASP.NET + XML)        
private void DropDownListProvince_SelectedIndexChanged(object sender, System.EventArgs e)
省市联动菜单(ASP.NET + XML)        
{
省市联动菜单(ASP.NET + XML)            
string CurrentPath = this.Server.MapPath(".");
省市联动菜单(ASP.NET + XML)
省市联动菜单(ASP.NET + XML)            
if(System.IO.File.Exists(CurrentPath + "\\Province.xml"))
省市联动菜单(ASP.NET + XML)            
{
省市联动菜单(ASP.NET + XML)                
this.DropDownListCity.Items.Clear();
省市联动菜单(ASP.NET + XML)
省市联动菜单(ASP.NET + XML)                System.Xml.XmlDocument doc 
= new System.Xml.XmlDocument();
省市联动菜单(ASP.NET + XML)                doc.Load(CurrentPath 
+ "\\Province.xml");
省市联动菜单(ASP.NET + XML)
省市联动菜单(ASP.NET + XML)                XmlNodeList nodes 
= doc.DocumentElement.ChildNodes[this.DropDownListProvince.SelectedIndex].ChildNodes;
省市联动菜单(ASP.NET + XML)
省市联动菜单(ASP.NET + XML)                
foreach(XmlNode node in nodes)
省市联动菜单(ASP.NET + XML)                
{
省市联动菜单(ASP.NET + XML)                    
this.DropDownListCity.Items.Add(node.Attributes["Name"].Value);
省市联动菜单(ASP.NET + XML)                    
int n = this.DropDownListCity.Items.Count - 1;
省市联动菜单(ASP.NET + XML)                    
if(node.Attributes["Name"].Value == this.City)
省市联动菜单(ASP.NET + XML)                    
{
省市联动菜单(ASP.NET + XML)                        
this.DropDownListCity.SelectedIndex = n;
省市联动菜单(ASP.NET + XML)                    }

省市联动菜单(ASP.NET + XML)                }

省市联动菜单(ASP.NET + XML)
省市联动菜单(ASP.NET + XML)                
if(this.DropDownListCity.SelectedIndex == -1)
省市联动菜单(ASP.NET + XML)                    
this.DropDownListCity.SelectedIndex = 0;
省市联动菜单(ASP.NET + XML)            }

省市联动菜单(ASP.NET + XML)            
else
省市联动菜单(ASP.NET + XML)            
{
省市联动菜单(ASP.NET + XML)                
this.LabelMessage.Text = "地市信息文件丢失!";
省市联动菜单(ASP.NET + XML)            }

省市联动菜单(ASP.NET + XML)        }

省市联动菜单(ASP.NET + XML)
省市联动菜单(ASP.NET + XML)    }

省市联动菜单(ASP.NET + XML)}


Province.xml 文件: /Files/lmjob/Province.xml

你可能感兴趣的:(asp.net)