Wrox Programmer Forums
|
BOOK: Beginning ASP.NET 3.5 : in C# and VB BOOK ISBN: 978-0-470-18759-3
This is the forum to discuss the Wrox book Beginning ASP.NET 3.5: In C# and VB by Imar Spaanjaars; ISBN: 9780470187593
Welcome to the p2p.wrox.com Forums.

You are currently viewing the BOOK: Beginning ASP.NET 3.5 : in C# and VB BOOK ISBN: 978-0-470-18759-3 section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old January 27th, 2010, 07:09 AM
Registered User
 
Join Date: Jan 2010
Posts: 4
Thanks: 0
Thanked 1 Time in 1 Post
Default CH13: LINQ and the bulleted list

Had no problem getting the bulleted list displayed from Chapter 13, but wanted to extend it a little. The idea was to turn the listitems in to links so I could create a "details" page for the user.

I changed the bulleted list definition to:

Code:
        <asp:BulletedList ID="lstReviews" runat="server" 
            DataSource='<%# Eval("Reviews") %>' DataTextField="Title" 
            DisplayMode="HyperLink" DataValueField='Id' 
            BulletStyle="Disc" >
which correctly converts the items to links. Problem is, this gives me links like:

localhost/Site/Reviews/17

where "17" is ths id from the record. What I need to do is inject some additional information to turn this in to

localhost/Site/Reviews/ReviewDetail.aspx?Id=17

Nothing I've tried has got me anywhere.

Any suggestions as to how I can achieve this please?

I've tred adding code to the DataValueField in the bulleted list and have tried to define a field in the LINQ statement - but that won't work because I have no direct access to add fields to the Reviews collection.

Thanks
Steve
 
Old January 27th, 2010, 08:10 AM
Authorized User
 
Join Date: Jan 2010
Posts: 34
Thanks: 5
Thanked 0 Times in 0 Posts
Default look at this

http://weblogs.asp.net/atlaszhu/arch...a-binding.aspx

it seems there is no easy way for that with bulletslist
but maybe I am wrong...

Barak

but...
you can replace the bulletlist with datalist:
Quote:
<asp:DataList ID="rptLetters" runat="server" DataSource='<%# Eval("Reviews")%>'>
<ItemTemplate>
<asp:HyperLink ID="cmdLetter" runat="server"
NavigateUrl='<%#GetLink(Eval("id"))%>'
Text='<%#Eval("Title")%>' />
</ItemTemplate>
</asp:DataList>
and in code behind:
Quote:
Protected Function GetLink(ByVal aId As Integer) As String
Return "~/Reviews/ReviewDetail.aspx?id=" & aId
End Function
that will work but you won't have the bullets :)

Last edited by barakros; January 27th, 2010 at 08:53 AM.. Reason: but you can do this:
 
Old January 27th, 2010, 09:23 AM
Registered User
 
Join Date: Jan 2010
Posts: 4
Thanks: 0
Thanked 1 Time in 1 Post
Default

Excellent, thank you.

I did look at that article on bulleted lists, but it seemed horribly complicated for such a simple requirement. The DataList seems much more sensible.

I'm not particularly bothered by the bullet point itself and can probably insert that using a little css code. If I generate myself a class with a background image (non-repeating) and a left margin - so the text appears to the right of the image, I'm sure I can make a credible looking bullet point.

Many thanks
Steve
 
Old January 27th, 2010, 09:32 AM
Imar's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
Default

Instead of a DataList, you can also use a Repeater. Put the <ul> and </ul> in the HeaderTemplate and FooterTemplate respectively, and add <li> elements to the ItemTemplate. That way, you have full control over the markup.

Hope this helps,

Imar
__________________
Imar Spaanjaars
http://Imar.Spaanjaars.Com
Follow me on Twitter

Author of Beginning ASP.NET 4.5 : in C# and VB, Beginning ASP.NET Web Pages with WebMatrix
and Beginning ASP.NET 4 : in C# and VB.
Did this post help you? Click the button below this post to show your appreciation!
 
Old January 27th, 2010, 12:43 PM
Registered User
 
Join Date: Jan 2010
Posts: 4
Thanks: 0
Thanked 1 Time in 1 Post
Default

Thanks Imar, I'll give that a try too.... it's all good learning, after all.

I think I became far too focussed on the example in the book when I should have just been playing around.

Steve
 
Old January 27th, 2010, 05:05 PM
Registered User
 
Join Date: Jan 2010
Posts: 4
Thanks: 0
Thanked 1 Time in 1 Post
Smile

On the off-chance that anyone else if following along, this is what I ended up with:

Code:
    <asp:Repeater ID="repReviews" runat="server">
    <ItemTemplate>
        <h3><asp:Literal ID="itemTitle" runat="server" Text='<%# Eval("Name") %>' /></h3>
        <asp:Repeater ID="lstGroups" runat="server"  DataSource='<%# Eval("Reviews") %>' >
            <HeaderTemplate><ul></HeaderTemplate>
            <ItemTemplate>
                <li>
                    <asp:HyperLink ID="cmdReview" runat="server" 
                            NavigateUrl='<%# GetUrl(Eval("Id")) %>' 
                            Text='<%# Eval("Title") %>' />
                </li>
            </ItemTemplate>
            <FooterTemplate></ul></FooterTemplate>
         </asp:Repeater>
    </ItemTemplate>
    </asp:Repeater>
and in the code behind:

Code:
    protected void Page_Load(object sender, EventArgs e)
    {
        using (PlanetWroxDataContext myReviews = new PlanetWroxDataContext())
        {
            var allGenres = from revs in myReviews.Genres
                            orderby revs.SortOrder
                            select new { revs.Name, revs.Reviews };
            repReviews.DataSource = allGenres;
            repReviews.DataBind();


        }
    }

    public string GetUrl(object Id)
    {
        return String.Format("~/Reviews/ReviewDetail.aspx?Id={0}", Id.ToString());
    }
Thanks for the help.

Steve
The Following User Says Thank You to sabarnett For This Useful Post:
Imar (January 27th, 2010)
 
Old January 27th, 2010, 06:54 PM
Imar's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
Default

Now that you're using the Repeater, you can drop the method in code and use this instead:

Code:
 
<asp:HyperLink ID="cmdReview" runat="server" 
    NavigateUrl='<%# "~/Reviews/ReviewDetail.aspx?Id=" + Eval("Id").ToString() %>' 
    Text='<%# Eval("Title") %>' />
Just a matter of preference, though....

Imar
__________________
Imar Spaanjaars
http://Imar.Spaanjaars.Com
Follow me on Twitter

Author of Beginning ASP.NET 4.5 : in C# and VB, Beginning ASP.NET Web Pages with WebMatrix
and Beginning ASP.NET 4 : in C# and VB.
Did this post help you? Click the button below this post to show your appreciation!





Similar Threads
Thread Thread Starter Forum Replies Last Post
ch13 more errors solved sporik BOOK: Beginning PHP 6, Apache, MySQL 6 Web Development ISBN: 9780470391143 0 December 4th, 2009 02:04 PM
HTML tags to automatically hang bulleted lines? cJeffreywang ASP.NET 2.0 Basics 1 February 6th, 2008 02:12 AM
bulleted list in grid view MunishBhatia ASP.NET 2.0 Basics 2 December 24th, 2007 04:26 AM
Ch13 Case Study 2 alecwood BOOK: Beginning Access 2003 VBA 0 October 18th, 2007 05:40 AM
Word Bulleted Paragraphs to HTML Unordered Lists schurli XSLT 10 August 21st, 2003 01:40 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.