Solved

Filtering an XML file by product name, displaying results in a datalist

Posted on 2013-12-01
2
230 Views
Last Modified: 2013-12-04
I am working in ASP.Net (vb) with a client's XML file (reduced from 319 entries to 3):

 
<?xml version= "1.0"?>
<products>
	<product id="001">
		<division>Division1</division>
		<name>AName</name>
		<model>Model1</model>
		<category></category>
		<datathumbURL>image.jpg</datathumbURL>
		<datasheetURL>document.pdf</datasheetURL>
		<thumbURL>image.png</thumbURL>
		<fullImageURL></fullImageURL>
		<description>Many, many words here</description>
		<contactSnail>address, city, state, zip</contactSnail>
		<contactDigits>phone</contactDigits>
		<contactWebsite>URL</contactWebsite>
	</product>
	<product id="002">
		<division>Division2</division>
		<name>BName</name>
		<model>Model2</model>
		<category></category>
		<datathumbURL>image.jpg</datathumbURL>
		<datasheetURL>document.pdf</datasheetURL>
		<thumbURL>image.png</thumbURL>
		<fullImageURL></fullImageURL>
		<description>many, many words here</description>
		<contactSnail>address, city, state, zip</contactSnail>
		<contactDigits>phone</contactDigits>
		<contactWebsite>URL</contactWebsite>
	</product>
	<product id="003">
		<division>Division3</division>
		<name>CName</name>
		<model>Model3</model>
		<category></category>
		<datathumbURL>image.jpg</datathumbURL>
		<datasheetURL>document.pdf</datasheetURL>
		<thumbURL>image.png</thumbURL>
		<fullImageURL></fullImageURL>
		<description>man, many words here</description>
		<contactSnail>address, city, state, zip</contactSnail>
		<contactDigits>phone</contactDigits>
		<contactWebsite>URL</contactWebsite>
	</product>
</products>

Open in new window


... and have created the sort and display code which works as expected (sorting the list of 319 products by name, division or model):

<script runat="server">
	Sub Page_Load

		dim dsProducts = New DataSet
		dsProducts.ReadXml(MapPath("products.xml"))
		
		Dim sid As String
		sid = Request.QueryString("sid")	
			
		If String.IsNullOrEmpty(Request.QueryString("sid")) Then
			dsProducts.Tables(0).DefaultView.Sort = "name, division, model ASC"			
		Elseif sid = "div" Then
			dsProducts.Tables(0).DefaultView.Sort = "division, name, model ASC"
		Elseif sid = "mod" Then
			dsProducts.Tables(0).DefaultView.Sort = "model, name, division ASC"	
		End If
	
		Dim dsProductsSort = dsProducts.Tables(0).DefaultView.ToTable()
		dlProducts.DataSource = dsProductsSort
		dlProducts.DataBind()
	End sub
</script>

<asp:DataList id="dlProducts" runat="server">
	<ItemTemplate>
		<a href="products-details.aspx?id=<%#Container.DataItem("id")%>" style="color:blue"> <%#Container.DataItem("name")%> | <%#Container.DataItem("model")%></a> | <%#Container.DataItem("division")%> 
	</ItemTemplate>
</asp:DataList>

Open in new window


The client would now like a page that will allow clicking on a letter of the alphabet (A - B - C, etc...) to see a list of product names beginning with that letter.  In the example XML code these are listed as AName, BName and CName.

Ideally, the results would be shown in the same datalist included above.

Easy enough to do using a database - I can't seem to wrap my ahead around making it work using an XML file as the datasource.  Shuffling fields in the XML file is an option if required.

Help?
0
Comment
Question by:henryroark
2 Comments
 
LVL 52

Accepted Solution

by:
Carl Tawn earned 500 total points
ID: 39689492
You should be able to add a RowFilter to the view based on the letter selected:
Dim filterLetter As String = "A"

...

If String.IsNullOrEmpty(Request.QueryString("sid")) Then
    dsProducts.Tables(0).DefaultView.Sort = "name, division, model ASC"
    dsProducts.Tables(0).DefaultView.RowFilter = "name like '" & filterLetter & "%'"
    ...
End If

Open in new window

0
 

Author Closing Comment

by:henryroark
ID: 39696268
Simple and perfect, thank you.  I had it in mind that it would be a complicated matter.  Knowing about .RowFilter opens up a lot of possibilities.
0

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Cannot kill Excel from taskmgr after Excel Export in VB 2014 6 35
xml with php question 5 29
VB.net/VSTO Excel Add-in 2 14
c#, case, if 4 16
Parsing a CSV file is a task that we are confronted with regularly, and although there are a vast number of means to do this, as a newbie, the field can be confusing and the tools can seem complex. A simple solution to parsing a customized CSV fi…
The Confluence of Individual Knowledge and the Collective Intelligence At this writing (summer 2013) the term API (http://dictionary.reference.com/browse/API?s=t) has made its way into the popular lexicon of the English language.  A few years ago, …
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…
In an interesting question (https://www.experts-exchange.com/questions/29008360/) here at Experts Exchange, a member asked how to split a single image into multiple images. The primary usage for this is to place many photographs on a flatbed scanner…

685 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question