how to filter content in a nested repeater

B

bob8000

Hello everyone,

I am completly new to ASP.NET and I am attempting to design a web site
with it and VB.NET

I have been following an example from a book which as taken me to the
point where I want to branch out and add my own things to the website.

I have a MS SQL Server database that I am using to store the
information I need for the website content

In the book example they use a Datalist with a nested repeater, which
I have working fine.

However the book example lists all the products on one page.

I would like to know how I could filter the results that are viewed on
each page

I will be listing ebooks on my site and have five catagories that I
need to list them in.

Computing
Internet
Finance
Food
Software


the repeater code of have is:


<ItemTemplate>
<asp:Image ID="Image4" runat="server" AlternateText='<%#
Eval("ItemName") %>' ImageAlign="Left"
ImageUrl='<%# Eval("GraphicFileName", "images/{0}")
%>' Style="margin: 5px 10px 5px 0px" />
<asp:Label ID="Label2" runat="server" Font-Bold="True"
Font-Size="1.2em" Text='<%# Eval("MenuItemType") %>'></asp:Label>
-
<asp:Label ID="Label3" runat="server" Font-Bold="True"
Font-Size="1.2em" Text='<%# Eval("ItemName") %>'></asp:Label><br />
<br />

<asp:Repeater ID="Repeater1" runat="server" DataSource='<
%# CType(Container.DataItem, DataRowView).CreateChildView("MenuLink")
%>' OnItemCommand="Repeater1_ItemCommand">
<ItemTemplate>
<span style="color: Firebrick;">
<asp:LinkButton ID="OrderItem" runat="server"
ToolTip="Add item to order" style="text-decoration:none;"
CommandArgument='<%# Eval("ItemPrice")
%>'>
<asp:Image ID="Image1" runat="server"
ImageUrl="~/images/TrolleyIcon.gif"
AlternateText="Add item to order button" />
<%#Eval("ItemPrice", "£{0:F2}")%> &nbsp;
</asp:LinkButton>
</span>
</ItemTemplate>
</asp:Repeater>
<br />
<br />
<asp:HyperLink ID="HyperLink1" runat="server" Font-
Bold="True" Font-Names="Corbel"
Font-Size="Large">Details</asp:HyperLink>
</ItemTemplate>


There is a field named menuItemType in my database and this lists the
catagories that I mentioned above.

So how would I modify this to just show items from the FOOD catagory
on the web page?

I hope I have explained myself OK

Thanks
 
D

David Wier

Add a dropdownlist at the top of the page - add items to the ddl that you
want to use as a filter, filling the VALUE of each item with the id of that
item in the database.
Then, starting with their sql query, add a where clause (however you'd like
it), based on the value
Select * from books WHERE category=@CategoryID

don't forget to either add a button to trigger this, or make your ddl's
autopostback property='True'

--
David Wier
MVP/ASPInsider
http://aspnet101.com
http://aspexpress.com


Hello everyone,

I am completly new to ASP.NET and I am attempting to design a web site
with it and VB.NET

I have been following an example from a book which as taken me to the
point where I want to branch out and add my own things to the website.

I have a MS SQL Server database that I am using to store the
information I need for the website content

In the book example they use a Datalist with a nested repeater, which
I have working fine.

However the book example lists all the products on one page.

I would like to know how I could filter the results that are viewed on
each page

I will be listing ebooks on my site and have five catagories that I
need to list them in.

Computing
Internet
Finance
Food
Software


the repeater code of have is:


<ItemTemplate>
<asp:Image ID="Image4" runat="server" AlternateText='<%#
Eval("ItemName") %>' ImageAlign="Left"
ImageUrl='<%# Eval("GraphicFileName", "images/{0}")
%>' Style="margin: 5px 10px 5px 0px" />
<asp:Label ID="Label2" runat="server" Font-Bold="True"
Font-Size="1.2em" Text='<%# Eval("MenuItemType") %>'></asp:Label>
-
<asp:Label ID="Label3" runat="server" Font-Bold="True"
Font-Size="1.2em" Text='<%# Eval("ItemName") %>'></asp:Label><br />
<br />

<asp:Repeater ID="Repeater1" runat="server" DataSource='<
%# CType(Container.DataItem, DataRowView).CreateChildView("MenuLink")
%>' OnItemCommand="Repeater1_ItemCommand">
<ItemTemplate>
<span style="color: Firebrick;">
<asp:LinkButton ID="OrderItem" runat="server"
ToolTip="Add item to order" style="text-decoration:none;"
CommandArgument='<%# Eval("ItemPrice")
%>'>
<asp:Image ID="Image1" runat="server"
ImageUrl="~/images/TrolleyIcon.gif"
AlternateText="Add item to order button" />
<%#Eval("ItemPrice", "£{0:F2}")%> &nbsp;
</asp:LinkButton>
</span>
</ItemTemplate>
</asp:Repeater>
<br />
<br />
<asp:HyperLink ID="HyperLink1" runat="server" Font-
Bold="True" Font-Names="Corbel"
Font-Size="Large">Details</asp:HyperLink>
</ItemTemplate>


There is a field named menuItemType in my database and this lists the
catagories that I mentioned above.

So how would I modify this to just show items from the FOOD catagory
on the web page?

I hope I have explained myself OK

Thanks
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,770
Messages
2,569,584
Members
45,075
Latest member
MakersCBDBloodSupport

Latest Threads

Top