I have a stored procedure which returns a mixture of plain columns, and one ‘column’ of xml datatype. As in:
Select
Field1,
Field2,
(
SELECT
Certification As '@certification',
LCID As '@lcid'
FROM
dbo.MemberCertifications
FOR XML PATH('certification'), TYPE, ROOT('certifications')
) AS Certifications
FROM
.......
I’m binding this result to a gridview, and I need the xml column to be bound to a nested repeater as it contains parent-child data.
I’ve tried setting the repeater datasource to the column name, as in:
<asp:Repeater ID="rp" runat="server" DataSource="<%# Eval("Certifications") %>">
<ItemTemplate>
<%#XPath("//@certification")%>
</ItemTemplate>
</asp:Repeater>
but that doesn’t work. It seems like it’s coming across as a plain string. If I just write a line break inside the ItemTemplate it includes a break for each char in the column!
I’ve also tried using an xmldatasource inline, but I get a parser error:
<asp:XmlDataSource ID="data_certs" runat="server" >
<%# Eval("Certifications") %>
</asp:XmlDataSource>
I’m at the end of my rope here – I’m at the point where I’m just going to build up my result in code by deserializing the xml. I don’t really need any gridview functionality anyway.
Any ideas?
Can you use LINQ to XML? You could load it using something like:
Basically what I am doing is converting the XML document to an anonymous type, which the repeater can reflect against. I’m sure some of the syntax is a little off (don’t remember if it’s a Value property or somethign else, my linq to XML is a little rusty 🙂 ) but that’s basically how it could be done from code.
Inline markup I don’t know if any approach works since it comes from the database. XmlDataSource requires a file and not so much from a database (at least from what I know, could be wrong).
HTH.