Hi, there, I'm trying to bind data from a hierarchal XML, It works fine with only a single level (see XML example 1) but when trying bind data from (XML Example 2) I cannot get the dataset to find the CommercialCardReport node.
XML Example 1
XML Example 2
Code behind
protected void Page_Load(object sender, EventArgs e)
{
if (!Page.IsPostBack)
{
binddata();
}
}
void binddata()
{
DataSet ds = new DataSet();ds.ReadXml(Server.MapPath(@"App_Data\Reports.xml"));
gv.DataSource = ds;
gv.DataBind();
}
protected void Editdata(object s, GridViewEditEventArgs e)
{
gv.EditIndex = e.NewEditIndex;
binddata();
}
protected void Deletedata(object s, GridViewDeleteEventArgs e)
{
binddata();
DataSet ds = gv.DataSource as DataSet;
ds.Tables[0].Rows[gv.Rows[e.RowIndex].DataItemIndex].Delete();
ds.WriteXml(Server.MapPath(@"App_Data\Reports.xml"));
binddata();
}
protected void Canceldata(object s, GridViewCancelEditEventArgs e)
{
gv.EditIndex = -1;
binddata();
}
protected void Updatedata(object s, GridViewUpdateEventArgs e)
{
int i = e.RowIndex;
string Position = (gv.Rows[e.RowIndex].FindControl("txtPosition") as TextBox).Text;
string Name = (gv.Rows[e.RowIndex].FindControl("txtLinkName") as TextBox).Text;
string Arch = (gv.Rows[e.RowIndex].FindControl("txtArch") as TextBox).Text;
string Dir = (gv.Rows[e.RowIndex].FindControl("txtDir") as TextBox).Text;string FileName = (gv.Rows[e.RowIndex].FindControl("txtFileName") as TextBox).Text;
gv.EditIndex = -1;
binddata();
DataSet ds = (DataSet)gv.DataSource;
ds.Tables[0].Rows[i]["ReportId"] = Position;
ds.Tables[0].Rows[i]["Name"] = Name;
ds.Tables[0].Rows[i]["HasArchiveFlag"] = Arch;
ds.Tables[0].Rows[i]["Directory"] = Dir;
ds.Tables[0].Rows[i]["FileName"] = FileName;
ds.WriteXml(Server.MapPath(@"App_Data\Reports.xml"));
binddata();
}
Code from the APSX page
OnPageIndexChanging="pageddata" OnRowDeleting="Deletedata"
OnRowUpdating="Updatedata" OnRowCancelingEdit="Canceldata"
AutoGenerateColumns="False" PageSize="3" CellPadding="4" ForeColor="#333333"
GridLines="None">
Would appreciate any help or hints, thank you.