Sign In| Join
Get Help:Ask a Question in our Forums|Report a Bug|More Help Resources
Last post Nov 22, 2012 10:18 AM by ggaurav
Member
529 Points
218 Posts
Nov 17, 2012 06:07 AM|LINK
Hello Friends,
I have an api which return XML to browser how can i read it and biind Listview from that XML?
Thnaks and Regards
Gaurav Bhandari
All-Star
118619 Points
18779 Posts
Nov 18, 2012 12:59 AM|LINK
ggaurav I have an api which return XML to browser how can i read it and biind Listview from that XML?
Hello,
Three main ways:
1)You can use XmlDataSource to bind to the xml file string and then bind the datasource to the GridView or any data presentation control.
2)If your xml can be serializable to a DataTable or DataSet by referring DataSet.ReadXml, you can just bind the DataTable to the GridView directly.
3)You can also try to use XmlDocument or XDocument to analyze all the nodes as well as values you wanna fetch out and bind to the GridView.
Nov 22, 2012 10:18 AM|LINK
Thanks Friends to give time to solve Problem. I got solution
<asp:XmlDataSource ID="XmlDataSource1" runat="server" DataFile="Name.xml" XPath="//response/page/results/book"> </asp:XmlDataSource> <asp:ListView ID="ListView1" runat="server" DataSourceID="XmlDataSource1"> <LayoutTemplate> <table id="Table1" runat="server" class="TableCSS"> <tr id="Tr1" runat="server" class="TableHeader"> <td id="Td1" runat="server"> isbn10 </td> <td id="Td2" runat="server"> isbn13 </td> <td id="Td4" runat="server"> title </td> <td id="Td5" runat="server"> author </td> <td id="Td6" runat="server"> binding </td> <td id="Td7" runat="server"> msrp </td> <td id="Td8" runat="server"> pages </td> <td id="Td9" runat="server"> publisher </td> <td id="Td10" runat="server"> published_date </td> <td id="Td11" runat="server"> rank </td> <td id="Td12" runat="server"> rating </td> </tr> <tr id="ItemPlaceholder" runat="server"> </tr> <tr id="Tr2" runat="server"> <td id="Td3" runat="server" colspan="2"> <asp:DataPager ID="DataPager1" runat="server"> <Fields> <asp:NextPreviousPagerField ButtonType="Link" /> <asp:NumericPagerField /> <asp:NextPreviousPagerField ButtonType="Link" /> </Fields> </asp:DataPager> </td> </tr> </table> </LayoutTemplate> <ItemTemplate> <tr class="TableData"> <td> <%# XPath("isbn10")%> </td> <td> <%# XPath("isbn13")%>' </td> <td> <%# XPath("title")%>' </td> <td> <%# XPath("author")%>' </td> <td> <%# XPath("binding")%>' </td> <td> <%# XPath("msrp")%>' </td> <td> <%# XPath("pages")%>' </td> <td> <%# XPath("publisher")%>' </td> <td> <%# XPath("published_date")%>' </td> <td> <%# XPath("rank")%>' </td> <td> <%# XPath("rating")%>' </td> </tr> </ItemTemplate> </asp:ListView>
ggaurav
Member
529 Points
218 Posts
How to Read XML and Bind list view
Nov 17, 2012 06:07 AM|LINK
Hello Friends,
I have an api which return XML to browser how can i read it and biind Listview from that XML?
Thnaks and Regards
Gaurav Bhandari
Decker Dong ...
All-Star
118619 Points
18779 Posts
Re: How to Read XML and Bind list view
Nov 18, 2012 12:59 AM|LINK
Hello,
Three main ways:
1)You can use XmlDataSource to bind to the xml file string and then bind the datasource to the GridView or any data presentation control.
2)If your xml can be serializable to a DataTable or DataSet by referring DataSet.ReadXml, you can just bind the DataTable to the GridView directly.
3)You can also try to use XmlDocument or XDocument to analyze all the nodes as well as values you wanna fetch out and bind to the GridView.
ggaurav
Member
529 Points
218 Posts
Re: How to Read XML and Bind list view
Nov 22, 2012 10:18 AM|LINK
Thanks Friends to give time to solve Problem. I got solution
<asp:XmlDataSource ID="XmlDataSource1" runat="server" DataFile="Name.xml" XPath="//response/page/results/book"> </asp:XmlDataSource> <asp:ListView ID="ListView1" runat="server" DataSourceID="XmlDataSource1"> <LayoutTemplate> <table id="Table1" runat="server" class="TableCSS"> <tr id="Tr1" runat="server" class="TableHeader"> <td id="Td1" runat="server"> isbn10 </td> <td id="Td2" runat="server"> isbn13 </td> <td id="Td4" runat="server"> title </td> <td id="Td5" runat="server"> author </td> <td id="Td6" runat="server"> binding </td> <td id="Td7" runat="server"> msrp </td> <td id="Td8" runat="server"> pages </td> <td id="Td9" runat="server"> publisher </td> <td id="Td10" runat="server"> published_date </td> <td id="Td11" runat="server"> rank </td> <td id="Td12" runat="server"> rating </td> </tr> <tr id="ItemPlaceholder" runat="server"> </tr> <tr id="Tr2" runat="server"> <td id="Td3" runat="server" colspan="2"> <asp:DataPager ID="DataPager1" runat="server"> <Fields> <asp:NextPreviousPagerField ButtonType="Link" /> <asp:NumericPagerField /> <asp:NextPreviousPagerField ButtonType="Link" /> </Fields> </asp:DataPager> </td> </tr> </table> </LayoutTemplate> <ItemTemplate> <tr class="TableData"> <td> <%# XPath("isbn10")%> </td> <td> <%# XPath("isbn13")%>' </td> <td> <%# XPath("title")%>' </td> <td> <%# XPath("author")%>' </td> <td> <%# XPath("binding")%>' </td> <td> <%# XPath("msrp")%>' </td> <td> <%# XPath("pages")%>' </td> <td> <%# XPath("publisher")%>' </td> <td> <%# XPath("published_date")%>' </td> <td> <%# XPath("rank")%>' </td> <td> <%# XPath("rating")%>' </td> </tr> </ItemTemplate> </asp:ListView>