dcsimg
Login | Register   
LinkedIn
Google+
Twitter
RSS Feed
Download our iPhone app
TODAY'S HEADLINES  |   ARTICLE ARCHIVE  |   FORUMS  |   TIP BANK
Browse DevX
Sign up for e-mail newsletters from DevX

By submitting your information, you agree that devx.com may send you DevX offers via email, phone and text message, as well as email offers about other products and services that DevX believes may be of interest to you. DevX will process your information in accordance with the Quinstreet Privacy Policy.


Tip of the Day
Language: ASP.NET
Expertise: Intermediate
Jun 20, 2006

WEBINAR:

On-Demand

Building the Right Environment to Support AI, Machine Learning and Deep Learning


How to Bind a GridView Control to XML in ASP.NET

In this example, your XML content is assumed to be ready and well formatted. To be compatible with a GridView, the XML document has to have a database-like format (table and records):

<countries>
  <country>
    <name>ANGOLA</name><code>24</code><size>1345 amp</size>
  </country>
  <country>
    <name>BENIN</name><code>204</code><size>435 amp</size>
  </country>
</countries>
  1. Drag a GridView component from the Toolbox.
  2. Add to your GridView a PreRender event.
  3. Write your code (see below) to bind a DataSet to the GridView.

public partial class _Default : System.Web.UI.Page
{
	protected void MyGridView_PreRender(object sender, EventArgs e)
	{
		// Creates a DataSet and loads it with an Xml Content
		DataSet aDataSet = new DataSet();
		aDataSet.ReadXml(new StringReader(aXmlDoc.OuterXml));

		// Bind the DataSet to the grid view
		GridView gv = (GridView)sender;
		gv.DataSource = aDataSet;
		gv.DataBind();
	}
}
Pascal Bazin
 
Comment and Contribute

 

 

 

 

 


(Maximum characters: 1200). You have 1200 characters left.

 

 

Sitemap
Thanks for your registration, follow us on our social networks to keep up-to-date