Hi all,
I am pretty new to ASP.NET and have been reading through Sams Teach Yourself ASP.NET in 24 Hours. All in all, not too bad a book. I'm currently working my way through a chapter on using data web controls, in particular, the Listview. The book describes how to set up a ListView so it will display data from an underlying database and display it on a website. So far, so good. Then it goes on to explain how to sort the records it has displayed. It suggests the following code:
CODE
<asp:ListView ID="ListView1" runat="server" DataSourceID="BooksDataSource">
<layouttemplate>
<h2>Welcome to my Bookstore</h2>
<asp:LinkButton ID="SortByTitle" runat="server" Text="Sort by Title" CommandName="Sort" CommandArgument="Title">
</asp:LinkButton>
|
<asp:LinkButton ID="SortByPrice" runat="server"
Text="Sort by Price"
CommandName="Sort"
CommandArgument="Price">
</asp:LinkButton>
<blockquote>
<asp:PlaceHolder runat="server" id="itemplaceholder">
</asp:PlaceHolder>
</blockquote>
</layouttemplate>
<itemtemplate>
<p>
<b><asp:Label id="titlelabel" runat="server" text='<%#eval("title") %>'></asp:label></b>
<br />
(Written by: <%#Eval("author")%>)
<br />
<b>Genre:</b>
<%#Eval("genre")%>
<br />
<b>Price:</b>
<%#Eval("price", "{0:c}")%>
<br />
<asp:CheckBox id="recommendedcheckbox" runat="server" checked='<%#Eval("Recommended") %>' text=Recommended enabled="false" />
<br />
</p>
</itemtemplate>
<itemseparatortemplate>
<hr />
</itemseparatortemplate>
</asp:ListView>
The 2 LinkButtons near the top supposedly sort the records by either Title or Price. I have the exact code given in the book, but it does not work. I was wondering if someone could take a look and try to identify what I was doing wrong.
Thanks,
Bort