Re: Bind xml file to datalist or gridview control

Thank you Mudassarkhan, your links have solved the first part of it for me. The first link provided a solution if I have the physical xml file to use as the datasource. What if the xml source is returned from a url which calls a function which returns the
xml data, in this case like this:

Re: Bind xml file to datalist or gridview control

Thank you Viksheku, but your example seems to only work for an xml 'file' with an xml extension in the file path. Looking for a way to read the xml from a URL that calls a function to generate and display the xml file.

Re: Bind xml file to datalist or gridview control

the same problem was faced by me but then I came to know that the problem is with xmlns (xml namespace) defined in the root tag. please check your xml file if you have the same. again the xml is recd. from the customer so the xmlns will always be in the
file so for that please create xsl file to remove xmlns from your xml file

Re: Bind xml file to datalist or gridview control

hi, your original post shows that you are using the xmldatasource control and definitely you started off well. Your mistake however is with how you pass the XPath to your xmldatasource, eg :

XPath="getWattsByScreenName/u"

needs to be :

XPath="root/getWattsByScreenName/u"

next mistake is that you are using Eval, perhaps you want to use XPath Instead so this :

<%# Eval("sn") %>
<%# Eval("p") %>

becomes :

<%# XPath("@sn") %>
<%# XPath("@p")%>

since you are binding to an xml file, consider using xpath expressions instead as above.

Making these 2 modifications as noted above, your code will work.

Lastly, you were asking :

Deeko

What if the xml source is returned from a url which calls a function which returns the xml data, in this case like this:

In this case, you can use the xmldatasource's Data property. This property takes an xml string Vs the DataFile property requires you pass it the path to file. The following code is based on your xml file, but this time as string content passed to the Data property.