henryroark
asked on
Filtering an XML file by product name, displaying results in a datalist
I am working in ASP.Net (vb) with a client's XML file (reduced from 319 entries to 3):
... and have created the sort and display code which works as expected (sorting the list of 319 products by name, division or model):
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?
<?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>
... 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>
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?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER