Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > ASP.NET and ASP > ASP.NET 3.5 > ASP.NET 3.5 Basics
Password Reminder
Register
| FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
ASP.NET 3.5 Basics If you are new to ASP or ASP.NET programming with version 3.5, this is the forum to begin asking questions. Please also see the Visual Web Developer 2008 forum.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the ASP.NET 3.5 Basics section of the Wrox Programmer to Programmer discussions. This is a community of tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
 
 
Thread Tools Search this Thread Display Modes
  #11 (permalink)  
Old April 7th, 2009, 01:23 PM
Imar's Avatar
Wrox Author
Points: 72,073, Level: 100
Points: 72,073, Level: 100 Points: 72,073, Level: 100 Points: 72,073, Level: 100
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2003
Location: Utrecht, Netherlands.
Posts: 17,089
Thanks: 80
Thanked 1,587 Times in 1,563 Posts
Default

Can't you do both? That is, bind the Picttures collection to the Repeater and then execute another query against the same result to get the first picture? E.g. after the call to databind add another query that gets the first image as a string?

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!
  #12 (permalink)  
Old April 8th, 2009, 12:03 PM
Authorized User
 
Join Date: Jan 2009
Posts: 51
Thanks: 0
Thanked 0 Times in 0 Posts
Default

I'm sorry, but this just does not seem to be working. If I take the url out of the repeater, it won't be customizable with the rest of the information. Everything that I have tried results in the following error messages:

Quote:
An invalid data source is being used for Repeater1. A valid data source must implement either IListSource or IEnumerable.
or

Quote:
Sequence operators not supported for type 'System.String'
I really want to figure this out, but feel as though I am going in circles. All I want is a repeater with the Album Name and the First Picture in the Album beneath it. Is Linq the way to go or should I be looking elsewhere. I have lost a lot of valuable time working with this and can't find the right direction. Please help
  #13 (permalink)  
Old April 8th, 2009, 01:00 PM
Imar's Avatar
Wrox Author
Points: 72,073, Level: 100
Points: 72,073, Level: 100 Points: 72,073, Level: 100 Points: 72,073, Level: 100
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2003
Location: Utrecht, Netherlands.
Posts: 17,089
Thanks: 80
Thanked 1,587 Times in 1,563 Posts
Default

IMO, LINQ is the way to do it, but you need to know how to do it. You need to understand the data bound and you need to understand some LINQ and how it works. Also, clearly stating your requirements, and thinking a bit about your design up front really helps. I, for one, am a bit lost about what it is you want exactly. You say you want a single item, yet you query a collection and use a repeater.

The erorr message says you can't use a singular object for a repeating control. So, you either need to feed a collection to the Repeater, or drop the repeater in facor of some other control that can handle a single value like an Image, a HyperLink or something similar.

Which one is it? Whhat exactly are you trying to accomplish?

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!
  #14 (permalink)  
Old April 8th, 2009, 01:56 PM
Authorized User
 
Join Date: Jan 2009
Posts: 51
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Instead of continuing in circles, I went back to the basics and wrote exaclty what I wanted to happen and tried to accomplish it step by step.

I created a page with a repeater that contains:
First Image in the Photo Album
Photo Album Name
Photo Album Id
Photo Album Owner


Code:
<div class="maintext">
       <asp:Repeater ID="Repeater1" runat="server">
        <ItemTemplate>
        <br/><asp:Image ID="Image1" ImageUrl="" runat="server" /><br />
        <br/><%#Eval("Name")%>
        <br/><%#Eval("Id")%>
        <br/><%#Eval("UserName")%> <br />
        </ItemTemplate></asp:Repeater>
        <p>
      <asp:Label ID="Label1" runat="server"></asp:Label> </p>
</div>
In the CB Page, I created the data source to get the Photo Album Name, ID, and Owner

Code:
Using myDatabaseContext As MyDataContext = New MyDataContext()
            Dim allAlbums = From albums In myDatabaseContext.PhotoAlbums _
                            Select albums.Name, albums.Id, albums.UserName
           
            Repeater1.DataSource = allAlbums
            Repeater1.DataBind()
This provided me with everything but the first picture in the photo album. So I went back and added a for each loop to see if I could correctly generate the first picture in the albums correctly:

Code:
 For Each album In allAlbums
                Dim albumId = album.Id
                Dim firstPic As String = (From pics In myDatabaseContext.Pictures _
                                          Where albumId = pics.PhotoAlbumId _
                                Select pics.ImageUrl).FirstOrDefault()
                Label1.Text += firstPic + "<br/>"

            Next
This produced a label with the url for the first picture in each album, exactly what I wanted.

What I can't do and haven't been able to do is find a way to bind the url's produced in the for each loop to the images in the repeater. Every time that I try to access the control using Repeater.FindControl("Image1") I an error. I apologize for the confusion. I am new to this and too stubborn to give up.
  #15 (permalink)  
Old April 9th, 2009, 02:47 AM
Imar's Avatar
Wrox Author
Points: 72,073, Level: 100
Points: 72,073, Level: 100 Points: 72,073, Level: 100 Points: 72,073, Level: 100
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2003
Location: Utrecht, Netherlands.
Posts: 17,089
Thanks: 80
Thanked 1,587 Times in 1,563 Posts
Default

Right, I think I finally understand your requirements. My initial example gave you the*first* albym, while you're after the first *picture* for each album. Something like this should work:

Code:
 
var albumWithFirstPic = from a in myDataContext.PhotoAlbums
     orderby a.Name
     select new { a.Name, FirstPicture = a.Pictures.FirstOrDefault() };
This selects the Album name and its first picture. You then get an anonymous type with a Name proeprty as a string and a FirstPicture property as a Picture which you can address in the Repeater like this:

Code:
 
<asp:Repeater ID="Repeater1" runat="server">
  <ItemTemplate>
    <h3><asp:Literal ID="Literal1" runat="server" Text='<%# Eval("Name") %>'></asp:Literal></h3>
    First Image: 
    <asp:Image ID="Image1" runat="server" ImageUrl='<%# Eval("FirstPicture.ImageUrl") %>' ToolTip='<%# Eval("FirstPicture.ToolTip") %>' />
  </ItemTemplate>
</asp:Repeater>
Notice statements like FirstPicture.ImageUrl to address the complex property type on the data item.

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!
  #16 (permalink)  
Old April 9th, 2009, 07:26 AM
Authorized User
 
Join Date: Jan 2009
Posts: 51
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Thank you so much. I finally got the desired results. I used the first or default, but didn't assign a name to it. Thanks again!!!
  #17 (permalink)  
Old April 9th, 2009, 12:30 PM
Imar's Avatar
Wrox Author
Points: 72,073, Level: 100
Points: 72,073, Level: 100 Points: 72,073, Level: 100 Points: 72,073, Level: 100
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2003
Location: Utrecht, Netherlands.
Posts: 17,089
Thanks: 80
Thanked 1,587 Times in 1,563 Posts
Default

You're welcome...

Rather than (or in addition to) posting a Thank You message, you can also click the Thank You button at the bottom of the relevant posts.... ;-)

Cheers,

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!
 


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Using LINQ for this book... Lee Dumond BOOK: ASP.NET 2.0 Website Programming Problem Design Solution ISBN: 978-0-7645-8464-0 3 January 9th, 2008 02:05 AM
how to automate selecting all items from list satish_k Pro VB.NET 2002/2003 0 October 3rd, 2006 06:23 AM
Selecting Items From Reports Brendan Bartley Access 3 June 9th, 2006 07:05 AM
displaying 6 items only having 20 items Lakshmi KS VB Components 1 February 17th, 2004 10:34 AM



All times are GMT -4. The time now is 05:57 PM.


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