Hello everyone I want to get the top 5 records from the xml file in asp.net. Please tell me how can I & lt; ASP: Repeater ID = "APP" Repeater 1 "Runat =" Server "> gt; ItemTemplate & gt; & lt ;! - content - & gt; & lt; div class =" post "& gt; & Lt; div class = "true" & gt; & lt; h2 & gt; & lt; a href = "#" & gt; & lt; ASP: label id = "LibLital" runat = "server" text = ' & Lt;% # Eval ("title")%> & gt; & Gt; & lt; / asp: Labels & gt; & lt; / a & gt; & lt; / h2 & gt; 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; 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: Labels & 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; Arvin & lt; / a & gt;
Comments
/ li> << div> & lt; / ItemTemplate & gt; & lt; / ASP: Repeater & gt;
C # code
var doc = XDocument.Load (server.MapPath ( "~ / Data / BlogContent.xml"); Var Results = doc.Descendants ("Post"). Where (x => 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}) Commandbysydending (x = & gt; x.id) Take (5); Repeater 1. Data Source = Results; Try using Repeater1.DataBind (); LINQ - Now after viewing XML, for empty positions Where to add permission var doc = XDocument.Load (@ "c: \ temp \ test.xml"); Var result = doc.Descendants ("Post"). Where (x = & gt; x.Element ("id")! = Null). Select (x = & gt; x). Order by dicing (x => int.Parse (..x.Element ("id"))) Take (5); If you want to move one step forward, you can create an anonymous type from the results like (I had to copy my spelling error in the description to describe it)
var doc = XDocument.Load (Server.MapPath ("~ / test.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}). Orderbivetecting (x = & gt; x.id). Take (5);
No comments:
Post a Comment