Dear all, below is my code to bind data from xml file and show in ListView.
How can i limit the number of records shown?
Dim DS As New DataSet()
DS.ReadXml(Server.MapPath("~/App_Data/news.xml"))
If DS.Tables(0).Rows.Count > 0 Then
Dim DR As DataRow() = DS.Tables(0).Select("type = 'Announcement'")
DS.Tables(0).DefaultView.Sort = "posted-date DESC"
DS.AcceptChanges()
If DR.Count > 0 Then
Me.lvAnnouncement.DataSource = DR.CopyToDataTable
Me.lvAnnouncement.DataBind()
Else
Me.lvAnnouncement.DataBind()
End If
End If
The description is little confusing, if there's no other condition and assume you want select n rows of data, .take(n) will be what you are looking for.
For example, when n=5:
Dim DS As New DataSet()
DS.ReadXml(Server.MapPath("~/App_Data/news.xml"))
If DS.Tables(0).Rows.Count > 0 Then
Dim DR As DataRow() = DS.Tables(0).Select("type = 'Announcement'").Take(5).ToArray()
DS.Tables(0).DefaultView.Sort = "posted-date DESC"
DS.AcceptChanges()
If DR.Count > 0 Then
Me.lvAnnouncement.DataSource = DR.CopyToDataTable
Me.lvAnnouncement.DataBind()
Else
Me.lvAnnouncement.DataBind()
End If
End If
Member
90 Points
726 Posts
How do I limit the number of records shown in an XML feed?
Aug 30, 2019 03:53 AM|kengkit|LINK
Dear all, below is my code to bind data from xml file and show in ListView.
How can i limit the number of records shown?
Participant
1840 Points
592 Posts
Re: How do I limit the number of records shown in an XML feed?
Sep 02, 2019 07:19 AM|Yang Shen|LINK
Hi kengkit,
The description is little confusing, if there's no other condition and assume you want select n rows of data, .take(n) will be what you are looking for.
For example, when n=5:
Dim DS As New DataSet() DS.ReadXml(Server.MapPath("~/App_Data/news.xml")) If DS.Tables(0).Rows.Count > 0 Then Dim DR As DataRow() = DS.Tables(0).Select("type = 'Announcement'").Take(5).ToArray() DS.Tables(0).DefaultView.Sort = "posted-date DESC" DS.AcceptChanges() If DR.Count > 0 Then Me.lvAnnouncement.DataSource = DR.CopyToDataTable Me.lvAnnouncement.DataBind() Else Me.lvAnnouncement.DataBind() End If End If
Best Regard,
Yang Shen
Member
90 Points
726 Posts
Re: How do I limit the number of records shown in an XML feed?
Sep 03, 2019 02:49 AM|kengkit|LINK
Thanks! It's exactly what i want to accomplish.
Meanwhile, i wonder what other condition is possible? tqtq