Reading XML into dataset / GridView c# : Read XML From URL

/* Posted April 7th, 2008 at 8:03am */
/* Filed under C#, Programming */

/* */

camping-xml-situps1.png

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();
}

  • Twitter
  • Digg
  • del.icio.us
  • Propeller
  • Reddit
  • Slashdot
  • StumbleUpon
  • Technorati
  • Mixx
  • Yahoo! Buzz
  • NewsVine
  • Facebook
  • Google Bookmarks

Related Posts


Related Stories

Related Tweets

3 Responses to “Reading XML into dataset / GridView c# : Read XML From URL”


Leave a Reply

or Login (not required)





HTML tags allowed: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>