[ # ] Reading XML into dataset / GridView c# : Read XML From URL
/* Posted April 7th, 2008 at 8:03am *//* Filed under C#, Programming */

So recently I had to read an xml file and then bind it to a dataset/gridview. I knew there had to be an easy way. This is how I ended up doing it:
aspx
asp :GridView ID="gvDocActivity" runat="server" AutoGenerateColumns="false" /
Code behind:
string URLString = "http://YOUR XML FILE";
XmlTextReader xmlTextReader = new XmlTextReader(URLString);
XmlDataDocument xdoc1 = new XmlDataDocument();
xdoc1.DataSet.ReadXml(xmlTextReader, XmlReadMode.InferSchema);
DataSet ds = xdoc1.DataSet;
if (ds.Tables.Count > 0)
{
gvDocActivity.DataSource = ds;
gvDocActivity.DataBind();
}













Leave a Reply
(* required)