tags:

views:

56

answers:

2

I have an application that extracts data from some xml that is stored in a database. In the Page_Load event I have the code extracting the xml out of the db, parsing the XML and saving the data I need in a list of Strings. Then I use this code:

dataGrid.DataSource = from field in stringList select field;
dataGrid.DataBind();

It prints out the list, but I need to have more control over it. The GridView properties in the GUI don't really reflect anything from the Page_Load event (which I'm not too surprised about) but I need to be able to generate hyperlinks with the data and using an HTMLTextWriter didn't work as the GridView just auto-escaped all the HTML. I am not really a .Net programmer and am not familiar with how this works. Should I have put the custom code somewhere other that the Page_Load event?

A: 

Have you thought about using an XmlDataSource to bind the grid to your data?

You should be able to load the XML data into the datasource using something like this:

XmlDocument doc = xmlDataSource.GetXmlDocument();
doc.LoadXml(xmlFromTheDatabase);
M4N
the XmlDataSource seems to be for xml files...my xml is coming from a database column, and I can't save the xml to a file before using it, because of security considerations.
W_P
@Paul: See my updated answer for how to load the XML into the datasource without writing it to a file first.
M4N
+2  A: 

http://msdn.microsoft.com/en-us/library/bb288031.aspx

you can use a template field and inside your item template, you would have a asp:hyperlink control. You would then use a <%#Bind(Container)%> in your asp:hyperlink) NavigateURL property)to bind

ram