Note that there are some explanatory texts on larger screens.

plurals
  1. POselect top 5 records from xml with C#
    text
    copied!<p>Hello everyone i wanna to fetch the top 5 records from xml file in asp.net.. Please tell me how can i do that i am fetching the data like this from xml </p> <p>Here is my repeator Markup i am binding my data with eval tag in repeator </p> <pre><code>&lt;asp:Repeater ID="Repeater1" runat="server"&gt; &lt;ItemTemplate&gt; &lt;!-- content --&gt; &lt;div class="post"&gt; &lt;div class="right"&gt; &lt;h2&gt;&lt;a href="#"&gt; &lt;asp:Label ID="lbltitle" runat="server" Text='&lt;%#Eval("title ") %&gt;'&gt;&lt;/asp:Label&gt;&lt;/a&gt;&lt;/h2&gt; &lt;asp:Label ID="lblcontent" runat="server" Text='&lt;%#Eval("Discription") %&gt;'&gt;&lt;/asp:Label&gt; &lt;/div&gt; &lt;div class="left"&gt; &lt;p class="dateinfo"&gt; &lt;asp:Label ID="lbldate" runat="server" Text='&lt;%#Eval("DT") %&gt;'&gt;&lt;/asp:Label&gt; &lt;span&gt;&lt;asp:Label ID="lblmnth" runat="server" Text='&lt;%#Eval("mnt") %&gt;'&gt;&lt;/asp:Label&gt;&lt;/span&gt;&lt;/p&gt; &lt;div class="post-meta"&gt; &lt;h4&gt;Post Info&lt;/h4&gt; &lt;ul&gt; &lt;li class="user"&gt;&lt;a href="#"&gt;Erwin&lt;/a&gt;&lt;/li&gt; &lt;li class="time"&gt;&lt;a href="#"&gt;12:30 PM&lt;/a&gt;&lt;/li&gt; &lt;li class="comment"&gt; &lt;asp:Label ID="Label1" runat="server" Text="Label"&gt;&lt;/asp:Label&gt; &lt;asp:HyperLink ID="HyperLink1" runat="server" NavigateUrl="~/PostComment.aspx" &gt;Comments&lt;/asp:HyperLink&gt;&lt;/li&gt; &lt;li class="permalink"&gt;&lt;a href="#"&gt;Permalink&lt;/a&gt;&lt;/li&gt; &lt;/ul&gt; &lt;/div&gt; &lt;/div&gt; &lt;/div&gt; &lt;/ItemTemplate&gt; &lt;/asp:Repeater&gt; </code></pre> <p>C# code</p> <pre><code> var doc = XDocument.Load(Server.MapPath("~/Data/BlogContent.xml")); var result = doc.Descendants("post").Where(x =&gt; x.Element("id") != null).Select(x =&gt; new { id = x.Element("id").Value, title = x.Element("title").Value, Description = x.Element("Discription").Value, dt = x.Element("dt").Value, mnt = x.Element("mnt").Value, yr = x.Element("yr").Value }).OrderByDescending(x =&gt; x.id).Take(5); Repeater1.DataSource = result; Repeater1.DataBind(); </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload