views:

1883

answers:

2

At present I am populating a standard .net 2.0 GridView & TreeView control using a physical XML document which uses an XSLT stylesheet. But i need to make the population of the grid more dynamic, while still using the XSLT style sheet

Does anyone know if it is possible to populate a standard .net 2.0 Gridview & TreeView control another way apart from using an a physical XML document?

I currently have some XML code stored in a database. Can i retreive it from the databe, apply XSLT style sheet on it and pass it onto the grid / tree without having to make a physical file?

A: 

It's possible to use XML to populate a GridView by using the XmlDataSource control. The following links should get you started:

XmlDataSource Web Server Control Overview (MSDN)

GridView Examples for ASP.NET 2.0: Accessing Data with the DataSource Controls (MSDN)

ASP.NET Quickstart Tutorials - XmlDataSource

The last link doesn't specifically cover binding a GridView to the XmlDataSource but does provide some useful reference code. You may need to transform your source XML to a format that the GridView can make sense of.

HTH
Kev

Kev
Why the downvote?
Kev
+1  A: 

If you are using an XmlDataSource you can set the Data property to any block of Xml. For example you could have a method which calls a webservice, returns some Xml, performs a transform and then assigns to the Data property. Calling DataBind on your grid will then update. It is important to note that if you have a value set in the DataFile property then this will always take precedence over anything you specify for Data.

You can use the exact same approach to retrieve some Xml from your database, transform and assign to XmldataSource.Data

HTH

Macros
Thanks for that... that was exactly what i needed... I didnt realise i could use the "Data" property of the XmldataSource instead of the "DataFile" property... Sorry I'm a total novice at this!
eMTeeN