Welcome to Dream.In.Code
Getting Help is Easy!

Join 136,542 Programmers for FREE! Get instant access to thousands of experts, tutorials, code snippets, and more! There are 1,818 people online right now. Registration is fast and FREE... Join Now!




Sorting ListView Records

 
Reply to this topicStart new topic

Sorting ListView Records, Following a tutorial, but the code does not work.

Bort
13 Aug, 2008 - 02:57 AM
Post #1

D.I.C Regular
Group Icon

Joined: 18 Sep, 2006
Posts: 419



Thanked: 4 times
Dream Kudos: 350
My Contributions
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>
            &nbsp; |&nbsp;
            <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
User is offlineProfile CardPM
+Quote Post

Fast ReplyReply to this topicStart new topic
Time is now: 12/2/08 10:36PM

Live Help!

Tutorials

Programming

Web Development

Reference Sheets

Code Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month