读到一个dataset里去
再在dataset里提取就可以了
再在dataset里提取就可以了
解决方案 »
- C#开发浏览器碰到的一个问题
- 如何用if语句用运算符判定 textbox.text的内容 急啊!!!
- 查询界面有多个条件,如何构造sql语句,
- 使用了未赋值的局部变量问题,请大家帮忙看一下……
- mdi子窗体的textbox为何禁用ctrl+v啊~~~~~~
- 用文本编辑器空格变成了问号~
- winform中如何在实现进度条渐变功能,或则能不能改一下进度颜色
- c#中如何得到一个字符串中首字母的字符代码,类似VB中的Asc(string)函数
- 哪里能下载到:Microsoft SQL Server 2000 Reporting Services
- 救命,oracle连接错误
- 分别位于两个DLL的SESSION,能相互通讯吗?
- 500求VSS服務器版本的下載地址
string xmlPath=@"d:\china.xml";
ds.ReadXml(xmlPath);我读了,读完了之后dataset中只有5列,
1-Province_Id,2-Code,3-Name,4-Type,5-Index
第三列显示内容:北京市,天津市,河北省。
没有其他的市县级信息,如何去找。。?
{
XmlDoc.Load(@"E:\test.xml"); foreach(XmlNode node in XmlDoc.DocumentElement.ChildNodes)
{
comboBox1.Items.Add(node.Attributes["Name"].Value);
}
comboBox1.SelectedIndex=0;
}
private void comboBox1_SelectedIndexChanged(object sender, System.EventArgs e)
{
comboBox2.Items.Clear(); string sXPath="/China/Province[@Name='" +
comboBox1.SelectedItem.ToString() + "']";
XmlNode node;
node=XmlDoc.DocumentElement.SelectSingleNode(sXPath);
foreach(XmlNode nod in node.ChildNodes)
{
comboBox2.Items.Add(nod.Attributes["CityName"].Value);
}
comboBox2.SelectedIndex=0;
}private void comboBox2_SelectedIndexChanged(object sender, System.EventArgs e)
{
comboBox3.Items.Clear(); string sXPath="/China/Province[@Name='" +
comboBox1.SelectedItem.ToString() + "']/City[@CityName='" +
comboBox2.SelectedItem.ToString() +"']";
XmlNode node;
node=XmlDoc.DocumentElement.SelectSingleNode(sXPath);
foreach(XmlNode nod in node.ChildNodes)
{
comboBox3.Items.Add(nod.Attributes["CountyName"].Value);
}
comboBox3.SelectedIndex=0;
}
string sXPath="/China/Province[@Name='" +
comboBox1.SelectedItem.ToString() + "']";
我认为应该是这句话的问题。我想问一下你的xml文件放在什么目录下面???string sXPath="/China/Province[。“
它会在 E 盘下去找 test.xml文件吗?
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
using System.Xml;namespace ReadXML
{
/// <summary>
/// Form1 的摘要说明。
/// </summary>
public class Form1 : System.Windows.Forms.Form
{
private System.Windows.Forms.ComboBox comboBox1;
private System.Windows.Forms.Button button1;
private System.Windows.Forms.ListBox listBox1;
private XmlDocument XmlDoc = null;
private System.Windows.Forms.ListBox listBox2;
/// <summary>
/// 必需的设计器变量。
/// </summary>
private System.ComponentModel.Container components = null; public Form1()
{
//
// Windows 窗体设计器支持所必需的
//
InitializeComponent(); //
// TODO: 在 InitializeComponent 调用后添加任何构造函数代码
//
} /// <summary>
/// 清理所有正在使用的资源。
/// </summary>
protected override void Dispose( bool disposing )
{
if( disposing )
{
if (components != null)
{
components.Dispose();
}
}
base.Dispose( disposing );
} #region Windows 窗体设计器生成的代码
/// <summary>
/// 设计器支持所需的方法 - 不要使用代码编辑器修改
/// 此方法的内容。
/// </summary>
private void InitializeComponent()
{
this.comboBox1 = new System.Windows.Forms.ComboBox();
this.button1 = new System.Windows.Forms.Button();
this.listBox1 = new System.Windows.Forms.ListBox();
this.listBox2 = new System.Windows.Forms.ListBox();
this.SuspendLayout();
//
// comboBox1
//
this.comboBox1.Location = new System.Drawing.Point(48, 48);
this.comboBox1.Name = "comboBox1";
this.comboBox1.Size = new System.Drawing.Size(121, 20);
this.comboBox1.TabIndex = 0;
this.comboBox1.SelectedIndexChanged += new System.EventHandler(this.comboBox1_SelectedIndexChanged);
//
// button1
//
this.button1.Location = new System.Drawing.Point(48, 16);
this.button1.Name = "button1";
this.button1.Size = new System.Drawing.Size(120, 23);
this.button1.TabIndex = 1;
this.button1.Text = "Load Province";
this.button1.Click += new System.EventHandler(this.button1_Click);
//
// listBox1
//
this.listBox1.ItemHeight = 12;
this.listBox1.Location = new System.Drawing.Point(48, 80);
this.listBox1.Name = "listBox1";
this.listBox1.Size = new System.Drawing.Size(120, 148);
this.listBox1.TabIndex = 2;
this.listBox1.SelectedIndexChanged += new System.EventHandler(this.listBox1_SelectedIndexChanged);
//
// listBox2
//
this.listBox2.ItemHeight = 12;
this.listBox2.Location = new System.Drawing.Point(176, 48);
this.listBox2.Name = "listBox2";
this.listBox2.Size = new System.Drawing.Size(120, 184);
this.listBox2.TabIndex = 3;
//
// Form1
//
this.AutoScaleBaseSize = new System.Drawing.Size(6, 14);
this.ClientSize = new System.Drawing.Size(352, 273);
this.Controls.Add(this.listBox2);
this.Controls.Add(this.listBox1);
this.Controls.Add(this.button1);
this.Controls.Add(this.comboBox1);
this.Name = "Form1";
this.Text = "Form1";
this.ResumeLayout(false); }
#endregion /// <summary>
/// 应用程序的主入口点。
/// </summary>
[STAThread]
static void Main()
{
Application.Run(new Form1());
} private void button1_Click(object sender, System.EventArgs e)
{
comboBox1.Items.Clear(); XmlDoc = new XmlDocument();
XmlDoc.Load("..\\..\\XMLFile1.xml"); foreach(XmlNode node in XmlDoc.DocumentElement.ChildNodes)
{
comboBox1.Items.Add(node.Attributes["Name"].Value);
}
comboBox1.SelectedIndex = 0;
} private void comboBox1_SelectedIndexChanged(object sender, System.EventArgs e)
{
listBox1.Items.Clear(); string sXPath="/China/Province[@Name='" +
comboBox1.SelectedItem.ToString() + "']";
XmlNode node;
node = XmlDoc.DocumentElement.SelectSingleNode(sXPath);
foreach(XmlNode nod in node.ChildNodes)
{
listBox1.Items.Add(nod.Attributes["CityName"].Value);
} listBox1.SelectedIndex=0;
} private void listBox1_SelectedIndexChanged(object sender, System.EventArgs e)
{
listBox2.Items.Clear(); string sXPath = "/China/Province[@Name='" +
comboBox1.SelectedItem.ToString() + "']/City[@CityName='" +
listBox1.SelectedItem.ToString() +"']";
XmlNode node;
node = XmlDoc.DocumentElement.SelectSingleNode(sXPath);
foreach(XmlNode nod in node.ChildNodes)
{
listBox2.Items.Add(nod.Attributes["CountyName"].Value);
}
listBox2.SelectedIndex = 0; }
}
}
{
//System.Xml.XmlDocument 表示 XML 文档
System.Xml.XmlDocument XmlDoc=new System.Xml.XmlDocument();
string xmlPath=Server.MapPath("xml file/Chinese.xml");
XmlDoc.Load(xmlPath);
//XmlNode 表示 XML 文档中的单个节点,
//DocumentElement获取文档的根 XmlElement。
foreach(XmlNode node in XmlDoc.DocumentElement.ChildNodes)
{
this.DropDownList1.Items.Add(node.Attributes["Name"].Value);
}
this.DropDownList1.SelectedIndex=0;
}
}private void DropDownList1_SelectedIndexChanged(object sender, System.EventArgs e)
{
System.Xml.XmlDocument XmlDoc=new System.Xml.XmlDocument();
this.DropDownList2.Items.Clear();
string sXPath="xml file/Chinese.xml/China/Province[@Name='"+ this.DropDownList1.SelectedItem.ToString() + "']";
XmlNode node;
node=XmlDoc.DocumentElement.SelectSingleNode(sXPath);
foreach(XmlNode nod in node.ChildNodes)
{
this.DropDownList2.Items.Add(nod.Attributes["CityName"].Value);
}
DropDownList2.SelectedIndex=0;
}
private void DropDownList2_SelectedIndexChanged(object sender, System.EventArgs e)
{
System.Xml.XmlDocument XmlDoc=new System.Xml.XmlDocument();
DropDownList3.Items.Clear();
string sXPath="/China/Province[@Name='" +
this.DropDownList1.SelectedItem.ToString() + "']/City[@CityName='" +
this.DropDownList2.SelectedItem.ToString() +"']";
XmlNode node;
node=XmlDoc.DocumentElement.SelectSingleNode(sXPath);
foreach(XmlNode nod in node.ChildNodes)
{
DropDownList3.Items.Add(nod.Attributes["CountyName"].Value);
}
DropDownList3.SelectedIndex=0;
}
}
string sXPath="/China/Province[@Name='"+ this.DropDownList1.SelectedItem.ToString() + "']";
---------------------------------------
先学学XPath吧!!!
http://www.w3schools.com/xpath/default.asp
<HTML>
<HEAD><meta http-equiv="Content-Type" content="text/html; charset=gb2312">
</HEAD>
<body text="#000000">
<form runat="server">
<P>
<asp:Image id="Image1" runat="server" ImageUrl="http://www.footo.cn/albums/10013/31/400cd6f1-356.jpg"></asp:Image>
<asp:DropDownList id="DropDownList1" runat="server" AutoPostBack="True"></asp:DropDownList>
<asp:DropDownList id="DropDownList2" runat="server" AutoPostBack=True EnableViewState=True></asp:DropDownList>
<asp:DropDownList id="DropDownList3" runat="server"></asp:DropDownList></P>
</form>
</body>
</HTML>
WebForm1.aspx.csusing System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Web;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;
using System.Data.OleDb;
using System.Xml;
namespace eMeng
{
/// <summary>
/// ShowList 的摘要说明。
/// </summary>
public class WebForm1 : System.Web.UI.Page
{
protected System.Web.UI.WebControls.DropDownList DropDownList1;
protected System.Web.UI.WebControls.DropDownList DropDownList2;
protected System.Web.UI.WebControls.DropDownList DropDownList3;
protected System.Web.UI.WebControls.Image Image1;private void Page_Load(object sender, System.EventArgs e)
{
if(!this.IsPostBack)
{
System.Xml.XmlDocument XmlDoc=new System.Xml.XmlDocument();XmlDoc.Load(Server.MapPath("a.xml"));
foreach(XmlNode node in XmlDoc.DocumentElement.ChildNodes)
{
this.DropDownList1.Items.Add(node.Attributes["Name"].Value);
}
DropDownList1.Items.Insert(0,"--请选择--");
this.DropDownList1.SelectedIndex=0;HttpContext.Current.Cache.Insert("XmlDoc",XmlDoc,null,DateTime.Now.AddYears(10),TimeSpan.Zero);
String scriptString = "<script language=JavaScript>";
scriptString += "if(document.all." + Image1.ClientID + ".height>100) document.all." + Image1.ClientID + ".height = 100";
scriptString += "</script>";if(!this.IsStartupScriptRegistered("Startup"))
this.RegisterStartupScript("Startup", scriptString);XmlDocument doc = new XmlDocument();
doc.LoadXml("<book>" +
"<title>Pride And Prejudice</title>" +
"</book>");
XmlElement elem = doc.CreateElement("","price","");
elem.InnerText = "ok";
doc.DocumentElement.AppendChild(elem);
Response.Write (Server.HtmlEncode(doc.OuterXml));
}
}#region Web Form Designer generated code
override protected void OnInit(EventArgs e)
{
//
// CODEGEN:该调用是 ASP.NET Web 窗体设计器所必需的。
//
InitializeComponent();
base.OnInit(e);
}/// <summary>
/// 设计器支持所需的方法 - 不要使用代码编辑器修改
/// 此方法的内容。
/// </summary>
private void InitializeComponent()
{
this.DropDownList1.SelectedIndexChanged += new System.EventHandler(this.DropDownList1_SelectedIndexChanged);
this.DropDownList2.SelectedIndexChanged += new System.EventHandler(this.DropDownList2_SelectedIndexChanged);
this.Load += new System.EventHandler(this.Page_Load);}
#endregionprivate void DropDownList2_SelectedIndexChanged(object sender, System.EventArgs e)
{
System.Xml.XmlDocument XmlDoc=new System.Xml.XmlDocument();XmlDoc = (System.Xml.XmlDocument)this.Cache.Get("XmlDoc");this.DropDownList3.Items.Clear();
string sXPath="//China/Province[@Name='"+ this.DropDownList1.SelectedItem.ToString() + "']/City[@CityName='"+this.DropDownList2.SelectedItem.ToString()+"']/County";
XmlNodeList nodes;
nodes=XmlDoc.DocumentElement.SelectNodes(sXPath);
foreach(XmlNode nod in nodes)
{
this.DropDownList3.Items.Add(nod.Attributes["CountyName"].Value);
}
DropDownList3.SelectedIndex=0;
}private void DropDownList1_SelectedIndexChanged(object sender, System.EventArgs e)
{System.Xml.XmlDocument XmlDoc=new System.Xml.XmlDocument();XmlDoc = (System.Xml.XmlDocument)this.Cache.Get("XmlDoc");
this.DropDownList2.Items.Clear();
string sXPath="//China/Province[@Name='"+ this.DropDownList1.SelectedItem.ToString() + "']/City";
XmlNodeList nodes;
nodes=XmlDoc.DocumentElement.SelectNodes(sXPath);
this.DropDownList3.Items.Clear();
foreach(XmlNode nod in nodes)
{
Response.Write (nod.Attributes["CityName"].Value);
this.DropDownList2.Items.Add(nod.Attributes["CityName"].Value);
}
DropDownList2.Items.Insert(0,"--请选择--");
DropDownList2.SelectedIndex=0;}
}
}
HttpContext.Current.Cache.Insert("XmlDoc",XmlDoc,null,DateTime.Now.AddYears(10),TimeSpan.Zero);
这句话不能够少。。
net_lover(孟子E章)老大的出马。
因为这句话:
HttpContext.Current.Cache.Insert("XmlDoc",XmlDoc,null,DateTime.Now.AddYears(10),TimeSpan.Zero);现在又出现了个问题,选中了第一个dropdownlist之后web页面上会显示其下的city,,
如何去掉这个显示。这个实例中,当选中 ”河北省“之后:
页面上出现:
石家庄市唐山市秦皇岛市邯郸市邢台市保定市张家口市承德市沧州市廊坊市衡水市 如何去掉这个显示。
页面上出现:
石家庄市唐山市秦皇岛市邯郸市邢台市保定市张家口市承德市沧州市廊坊市衡水市 如何去掉这个显示。我想选中 ”河北省“之后只是DropDownList2中有相应的变化。页面上不出现类似的信息如:“石家庄市唐山市秦皇岛市邯郸市邢台市保定市张家口市承德市沧州市廊坊市衡水市 ”