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

  • Digg
  • del.icio.us
  • Propeller
  • Reddit
  • Slashdot
  • StumbleUpon
  • Technorati
  • Mixx
  • NewsVine
  • Blogsvine
  • Facebook
  • Google
  • TwitThis


Random Posts

Leave a Reply


*


* (not published, used to display your gravatar)



(* required)

Anything Geeky Goes!

Highlights

Featured Wii

Featured iPhone

Featured PSP/PS3

Featured A/V

Related Links

Archives

Products Highlight


Featured Sites

Categories

Subscribe

Recent Posts

Commentors

Other Links