This is a migrated thread and some comments may be shown as answers.

Databinding to an XmlDocument

2 Answers 215 Views
GridView
This is a migrated thread and some comments may be shown as answers.
superold
Top achievements
Rank 1
superold asked on 31 Jul 2007, 04:56 PM
Hi!
I know it's sort of strange to do it, but can the grid bind to a XmlDocument? Maybe give Xpaths to the columns to show, it would be fantastic.

What I want to accomplish is to show in a datagrid the results of an xpath expression on SelectNodes. And it should be fast (150 000 elements).

Any idea on how to accomplish this? XmlNodeList implements IEnumerable, shouldnt it be able to bind?

Anyways, I thought it would be a neat feature to be able to do it directly.

Thanks,
/ jorge

2 Answers, 1 is accepted

Sort by
0
superold
Top achievements
Rank 1
answered on 01 Aug 2007, 10:12 AM
Hi. I found out that it is possible to do it in ASP.NET. Is it possible to do it with the Winforms grid?
/ jorge

<asp:DataGrid id="DataGrid1" AutoGenerateColumns="False" runat="server">
<Columns>
<asp:TemplateColumn HeaderText ="ProductCode">
<ItemTemplate>
<%# ((System.Xml.XmlNode)Container.DataItem).Attributes["pcode"].Value %>
</ItemTemplate>
</asp:TemplateColumn>
</Columns>
</asp:DataGrid>

XmlDocument xmldoc = new XmlDocument();
xmldoc.Load(Server.MapPath("products.xml"));
XmlNodeList xmlnodes = xmldoc.SelectNodes("NewDataSet/Product/ProductID");
DataGrid1.DataSource = xmlnodes;
DataGrid1.DataBind ();

0
Julian Benkov
Telerik team
answered on 01 Aug 2007, 04:22 PM
Currently RadGridView does not support generic binding to XML. A possible workaround is to create a data set and use its ReadXML method  ( http://msdn2.microsoft.com/en-us/library/Aa325639(VS.71).aspx ) and then load the dataset as a data source of the RadGridView. Please note that you may experience some problems with loading the XML inside the data set because of namespaces and other parameters of the XML data in the file.


Sincerely yours,
Julian Benkov
the Telerik team

Instantly find answers to your questions at the new Telerik Support Center
Tags
GridView
Asked by
superold
Top achievements
Rank 1
Answers by
superold
Top achievements
Rank 1
Julian Benkov
Telerik team
Share this question
or