日期:2014-05-19  浏览次数:20471 次

C#读取xml数据并进行分页 !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
C#读取xml数据并进行分页   !!!!!!!!!!

有例子更好,谢谢大家了!!!!!!!!!!

------解决方案--------------------
读取相同目录下的XML文件
private void loadData()
{
DataSet mydataset = new DataSet();
//读取xml文件
mydataset.ReadXml(Server.MapPath( "databackup.xml "));
//grid.DataSource = mydataset.Tables[0];
//grid.DataBind();
}
------解决方案--------------------
namespace admin
{
using System;
using System.Data;
using System.Drawing;
using System.Web;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;
using System.Xml;

/// <summary>
/// AdminMenu 的摘要说明。
/// </summary>
public class AdminMenu : System.Web.UI.UserControl
{
protected System.Web.UI.WebControls.DataList MyList;

private void Page_Load(object sender, System.EventArgs e)
{
string selectionID = Request.Params[ "selection "];

if ( selectionID != null)
{
MyList.SelectedIndex = Int32.Parse(selectionID);
}
BindMenu(Session[ "RoleId "].ToString());

}

/// <summary>
/// 从XML文件读入管理员目录的列表项目,并绑定到目录
/// </summary>
private void BindMenu(string roleId)
{
System.Xml.XmlDocument doc = new XmlDocument();
doc.Load(Server.MapPath( "AdminMenu.xml "));

XmlNode itemNode = doc.DocumentElement;


DataTable menuList = new DataTable();

menuList.Columns.Add( "ItemName ");
menuList.Columns.Add( "ItemUrl ");

string itemName, itemUrl, itemRole;
string []rowItem = new string[2];

foreach (XmlNode node in itemNode)
{
itemRole = node.Attributes[ "RoleId "].Value;
if (roleId == "2 ")
{
if ( itemRole == roleId)
{
itemName = node.Attributes[ "ItemName "].Value;
itemUrl = node.Attributes[ "ItemUrl "].Value;

rowItem[0] = itemName;
rowItem[1] = itemUrl;

menuList.Rows.Add(rowItem);
}
}
else
{
itemName = node.Attributes[ "ItemName "].Value;
itemUrl = node.Attributes[ "ItemUrl "].Value;

rowItem[0] = itemName;
rowItem[1] = itemUrl;

menuList.Rows.Add(rowItem);
}


}

MyList.DataSource = menuList.DefaultView;
MyList.DataBind();


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

/// <summary>
/// 设计器支持所需的方法 - 不要使用代码编辑器
/// 修改此方法的内容。
/// </summary>
private void InitializeComponent()
{
this.Load += new System.EventHandler(this.Page_Load);

}
#endregion
}
}

------解决方案--------------------
<html>
<head>
<script type= "text/javascript ">
function movenext()
{
x=xmldso.recordset
if (x.absoluteposition < x.recordcount)
{
x.movenext()
}
}
function moveprevious()
{
x=xmldso.recordset
if (x.absoluteposition > 1)