日期:2014-05-20  浏览次数:20951 次

Asp.net加XML问题?
strResultInfo=webMail.GetDepartment(userId,doMain,account,sign);

  strResultInfo返回值为:
  <?xml version="1.0" encoding="GB2312" ?> 
- <departmentList>
- <department>
  <departmentId>2</departmentId> 
  <domainId>224556</domainId> 
  <departmentName>人力资源</departmentName> 
  <description>人力资源</description> 
  <depId>0</depId> 
  <rank>null</rank> 
  <type>null</type> 
  <top>0</top> 
  <resv1>0</resv1> 
  <resv2>renliziyuan</resv2> 
  </department>
- <department>
  <departmentId>3</departmentId> 
  <domainId>224556</domainId> 
  <departmentName>财务</departmentName> 
  <description>null</description> 
  <depId>0</depId> 
  <rank>null</rank> 
  <type>null</type> 
  <top>1</top> 
  <resv1>null</resv1> 
  <resv2>null</resv2> 
  </department>
  </departmentList>

  #region XML

  XmlDocument xmlDoc = new XmlDocument();
  xmlDoc.LoadXml(strResultInfo);
  XmlNodeList mailList = xmlDoc.SelectNodes("/departmentList/department");

  //lblCount.Text = mailList.Count.ToString();

  for (int i = 0; i < mailList.Count; i++)
  {
  //这是DropDownList控件
  dlMailList.DataSource = strResultInfo;
  dlMailList.DataTextField = mailList[i].SelectSingleNode("departmentId").InnerText.ToString();
  dlMailList.DataValueField = mailList[i].SelectSingleNode("departmentName").InnerText.ToString();
  this.DataBind();
  }
我想实现把xml分别两个值(departmentId,departmentName)循环遍历绑定到DropDownList控件,可是报错误为:DataBinding:“System.Char”不包含名为“2”的属性。

------解决方案--------------------
分别遍历...