Bind Linq to XML to a GridView with AllowPaging = True

EDN Admin

Well-known member
Joined
Aug 7, 2010
Messages
12,794
Location
In the Machine
<p align=left><font face=Arial size=2>Hello, I have a XML file with parts information, which includes Part Name, Description, and Image. I am using Linq to XML to load and parse XML file, I bind results to a GridView control with allow paging enabled. </font>
<p align=left> 
<p align=left>It is giving message that the source for GridView control does not support Server Side paging. How do I convert it or set it as DataSet or Dataview so I can use the paging in Gridview? Here is the Code;
<p align=left>  <font color="#0000ff" size=2>
<p align=left>
<div class=codeseg>
<div class=codecontent>
<div class=codesniptitle><span style="width:100% Code Snippet <font color="#0000ff" size=2>
<p align=left>string</font><font size=2> xFile = </font><font color="#2b91af" size=2>XDocument</font><font size=2>.Load(</font><font color="#a31515" size=2>"products.xml"</font><font size=2>).ToString();
<p align=left>  <font color="#2b91af" size=2>
<p align=left>XDocument</font><font size=2> xmlParts = </font><font color="#2b91af" size=2>XDocument</font><font size=2>.Parse(xFile);
<p align=left></font><font color="#0000ff" size=2>var</font><font size=2> products = </font><font color="#0000ff" size=2>from</font><font size=2> product </font><font color="#0000ff" size=2>in</font><font size=2> xmlParts.Descendants(</font><font color="#a31515" size=2>"product"</font><font size=2>)
<p align=left></font><font color="#0000ff" size=2>where</font><font size=2> product.Element(</font><font color="#a31515" size=2>"type"</font><font size=2>).Value == </font><font color="#a31515" size=2>"Automated" </font><font size=2>
<p align=left></font><font color="#0000ff" size=2>select</font><font size=2> </font><font color="#0000ff" size=2>new</font><font size=2> </font><font color="#2b91af" size=2>GruberProduct </font><font size=2>
<blockquote dir=ltr style="margin-right:0px
<p align=left>{
<blockquote dir=ltr style="margin-right:0px
<p align=left>Type = ((</font><font color="#0000ff" size=2>string</font><font size=2>)product.Element(</font><font color="#a31515" size=2>"type"</font><font size=2>)).Trim(),
<p align=left>Name = ((</font><font color="#0000ff" size=2>string</font><font size=2>)product.Element(</font><font color="#a31515" size=2>"name"</font><font size=2>)).Trim(),
<p align=left>Description = ((</font><font color="#0000ff" size=2>string</font><font size=2>)product.Element(</font><font color="#a31515" size=2>"description"</font><font size=2>)).Trim(),
<p align=left>ImagePath = ((</font><font color="#0000ff" size=2>string</font><font size=2>)product.Element(</font><font color="#a31515" size=2>"image"</font><font size=2>)), </blockquote>
<p align=left>}; </blockquote>
<p align=left></font><font color="#008000" size=2>  </font><font size=2><font size=2>
<p align=left>Gridview1.DataSource = products;
<p align=left>Gridview1.DataBind(); </font></font></font>
<p align=left> 
<p align=left>  </font><font size=2>
<font size=2><font size=2>
<p align=left>Thank you,
<p align=left> 
<p align=left>Gus</font></font></font>

View the full article
 
Back
Top