?
=?iso-8859-1?Q?=BF_Mahesh_Kumar?=
I have created a XML file as datasource which i 'm binding to a grid view control.
During runtime I'm capturing items in XML file and displaying in a GRID VIEW control. but i want to remove or flush the XML file content on page load. I tried parentnode.removeall () but no use..
(1) how to clean/delete the XML file nodes on page load for using as DATA SOURCE which again i'm binding to Grid view..??
(2) and also on page refresh my gird duplicating the items from XML file...how to avoid duplication of items in Grid...?
----------------------------------------------------------------code on button click (save)
XmlDocument xdoc = new XmlDocument();
xdoc.Load(Server.MapPath("XMLFILES\\ReferrelGrid.xml"));
XmlElement Parentnode = xdoc.CreateElement("ITEMS");
xdoc.DocumentElement.PrependChild(Parentnode);
XmlElement locationnode = xdoc.CreateElement("VID");
XmlElement statenode = xdoc.CreateElement("YesNo");
XmlText locationtext = xdoc.CreateTextNode(((TextBox)rptrItem.FindControl(chkstr)).Text);
XmlText statetext = xdoc.CreateTextNode("True");
Parentnode.AppendChild(locationnode);
Parentnode.AppendChild(namenode);
Parentnode.AppendChild(statenode);
locationnode.AppendChild(locationtext);
namenode.AppendChild(nametext);
statenode.AppendChild(statetext);
xdoc.Save(Server.MapPath("XMLFILES\\ReferrelGrid.xml"));
DataSet dstXML = new DataSet();
dstXML.ReadXml(Server.MapPath("XMLFILES\\ReferrelGrid.xml"));
Myfirstgrid.DataSource = dstXML;
Myfirstgrid.DataBind(); <<<< ------------------- binding the grid view control to that XML Offline file
During runtime I'm capturing items in XML file and displaying in a GRID VIEW control. but i want to remove or flush the XML file content on page load. I tried parentnode.removeall () but no use..
(1) how to clean/delete the XML file nodes on page load for using as DATA SOURCE which again i'm binding to Grid view..??
(2) and also on page refresh my gird duplicating the items from XML file...how to avoid duplication of items in Grid...?
----------------------------------------------------------------code on button click (save)
XmlDocument xdoc = new XmlDocument();
xdoc.Load(Server.MapPath("XMLFILES\\ReferrelGrid.xml"));
XmlElement Parentnode = xdoc.CreateElement("ITEMS");
xdoc.DocumentElement.PrependChild(Parentnode);
XmlElement locationnode = xdoc.CreateElement("VID");
XmlElement statenode = xdoc.CreateElement("YesNo");
XmlText locationtext = xdoc.CreateTextNode(((TextBox)rptrItem.FindControl(chkstr)).Text);
XmlText statetext = xdoc.CreateTextNode("True");
Parentnode.AppendChild(locationnode);
Parentnode.AppendChild(namenode);
Parentnode.AppendChild(statenode);
locationnode.AppendChild(locationtext);
namenode.AppendChild(nametext);
statenode.AppendChild(statetext);
xdoc.Save(Server.MapPath("XMLFILES\\ReferrelGrid.xml"));
DataSet dstXML = new DataSet();
dstXML.ReadXml(Server.MapPath("XMLFILES\\ReferrelGrid.xml"));
Myfirstgrid.DataSource = dstXML;
Myfirstgrid.DataBind(); <<<< ------------------- binding the grid view control to that XML Offline file