Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > ASP.NET and ASP > ASP.NET 4 > BOOK: Beginning ASP.NET 4 : in C# and VB
Password Reminder
Register
| FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
BOOK: Beginning ASP.NET 4 : in C# and VB
This is the forum to discuss the Wrox book Beginning ASP.NET 4: in C# and VB by Imar Spaanjaars; ISBN: 9780470502211
Welcome to the p2p.wrox.com Forums.

You are currently viewing the BOOK: Beginning ASP.NET 4 : in C# and VB 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
Reply
 
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old July 29th, 2012, 01:00 PM
Friend of Wrox
Points: 1,469, Level: 15
Points: 1,469, Level: 15 Points: 1,469, Level: 15 Points: 1,469, Level: 15
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Oct 2009
Posts: 341
Thanks: 14
Thanked 3 Times in 3 Posts
Smile get first picture of specified album

Hello Imar,

On a page I am filtering pictures according albums. I want that in a repeater only first picture be shown for a selected album from dropdownlist, but I am getting eror

"An invalid data source is being used for Repeater2. A valid data source must implement either IListSource or IEnumerable."

My code is below

Code:
<asp:DropDownList ID="DropDownList1" runat="server" AutoPostBack="True" DataTextField="Name" DataValueField="Id" AppendDataBoundItems="true">
      <asp:ListItem Value="">Select Plot</asp:ListItem>
</asp:DropDownList>

<asp:Repeater ID="Repeater2" runat="server">
<ItemTemplate>
      <asp:Image ID="Image2" runat="server" ImageUrl='<%# Eval("SmallImageUrl") %>'/>
</ItemTemplate>
</asp:Repeater>
and code behind is as below

Code:
protected void Page_Load(object sender, EventArgs e)
{
        if (DropDownList1.SelectedValue != string.Empty)
        {
            using (ASPNETDBEntities myEntities = new ASPNETDBEntities())
            {
                int albumId = Convert.ToInt32(DropDownList1.SelectedValue);
                var myPics = (from pic in myEntities.Pictures
                              where pic.AlbumId == albumId
                              select pic).FirstOrDefault();
                Repeater2.DataSource = myPics;
                Repeater2.DataBind();
            }
        }
}
Please tell me what I am doing wrong and how I can get only first picture in selected album

Many thanks
Reply With Quote
  #2 (permalink)  
Old July 29th, 2012, 02:15 PM
Imar's Avatar
Wrox Author
Points: 72,055, Level: 100
Points: 72,055, Level: 100 Points: 72,055, Level: 100 Points: 72,055, Level: 100
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2003
Location: Utrecht, Netherlands.
Posts: 17,086
Thanks: 80
Thanked 1,587 Times in 1,563 Posts
Default

Hi there,

Your LINQ code is fine, but you cannot use a Repeater to display its results. As its name implies, it's used to display multipe items, while First gives you a single instance. You have a few options:

1. Add this single instance to a list, such as a List<Picture> and use that for the DataSource. Feels a bit odd though as you really only have single instance.

2. Use a different control such as a DetailsView which si designed to display a single record at a time.

3. Don't use a Data Control, but a simple Image control instead and assign its ImageUrl from code behind directly.

Hope this helps.

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!
Reply With Quote
  #3 (permalink)  
Old July 30th, 2012, 02:41 PM
Friend of Wrox
Points: 1,469, Level: 15
Points: 1,469, Level: 15 Points: 1,469, Level: 15 Points: 1,469, Level: 15
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Oct 2009
Posts: 341
Thanks: 14
Thanked 3 Times in 3 Posts
Smile

Hello Imar,
I have replaced Repeater with Details View and now it is not giving error.
But I am not getting the result what I want.


code behind is
Code:
int albumId = Convert.ToInt32(DropDownList1.SelectedValue);
var myPic = new List<Picture> { (from pic in myEntities.Pictures
                                                  where pic.AlbumId == albumId
                                                  select pic).FirstOrDefault()};

                DetailsView1.DataSource = myPic;
                DetailsView1.DataBind();
and the markup code is

Code:
<asp:DetailsView ID="DetailsView1" runat="server" Height="50px" Width="125px" AutoGenerateRows="false">
        <Fields>
            <asp:TemplateField>
                <ItemTemplate>
                    <asp:HyperLink ID="HyperLink2" runat="server" NavigateUrl='<%# Eval("LargeImageUrl") %>' ClientIDMode="Static"><asp:Image ID="Image2" runat="server" ImageUrl='<%# Eval("SmallImageUrl") %>' /></asp:HyperLink>
                </ItemTemplate>
            </asp:TemplateField>
        </Fields>
    </asp:DetailsView>
is it that what you meant?

In the second repeater I actually wanted to hyperlink the first image in selected album.

Without any databound controls in simple html I have few images which are connected to first image by ID attribute and by applying some javascript, a cool effect is given.

Code:
<a href="bigimage1" rel="zoom-id:hyperlink2;" rev="mediumimage1"><img src="smallimage1"/></a>

<a href="bigimage2" rel="zoom-id:hyperlink2;" rev="mediumimage2"><img src="smallimage2"/></a>

<a href="bigimage3" rel="zoom-id:hyperlink2;" rev="mediumimage3"><img src="smallimage3"/></a>


<a href="bigimage1" id="hyperlink2" rel="zoom-width:300px; zoom-height:200px;"><img src="smallimage1"/></a>
I want to get all these values dynamically so I used repeater and detailsview

Code:
<asp:Repeater ID="Repeater1" runat="server" DataSourceID="EntityDataSource1">
            <ItemTemplate>
                <asp:HyperLink ID="HyperLink1" runat="server" NavigateUrl='<%# Eval("LargeImageUrl") %>' rel="zoom-id:HyperLink2" rev='<%# Eval("MediumImageUrl") %>'><asp:Image ID="Image1" runat="server" ImageUrl='<%# Eval("SmallImageUrl") %>' /></asp:HyperLink>
            </ItemTemplate>
            </asp:Repeater>

<asp:DetailsView ID="DetailsView1" runat="server" Height="50px" Width="125px" AutoGenerateRows="false">
        <Fields>
            <asp:TemplateField>
                <ItemTemplate>
                    <asp:HyperLink ID="HyperLink2" runat="server" NavigateUrl='<%# Eval("LargeImageUrl") %>' ClientIDMode="Static" rel="zoom-width:300px; zoom-height:200px;"><asp:Image ID="Image2" runat="server" ImageUrl='<%# Eval("SmallImageUrl") %>' /></asp:HyperLink>

But it is not producing same result. where might be error?

Many thanks
Reply With Quote
  #4 (permalink)  
Old July 30th, 2012, 02:45 PM
Imar's Avatar
Wrox Author
Points: 72,055, Level: 100
Points: 72,055, Level: 100 Points: 72,055, Level: 100 Points: 72,055, Level: 100
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2003
Location: Utrecht, Netherlands.
Posts: 17,086
Thanks: 80
Thanked 1,587 Times in 1,563 Posts
Default

>> But I am not getting the result what I want.

And what is the result you're getting?

Also,mwhy don't you ditch the DetailsView and simply use the HyperLink and image controls directly? Much simpler....

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!
Reply With Quote
  #5 (permalink)  
Old July 30th, 2012, 03:17 PM
Friend of Wrox
Points: 1,469, Level: 15
Points: 1,469, Level: 15 Points: 1,469, Level: 15 Points: 1,469, Level: 15
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Oct 2009
Posts: 341
Thanks: 14
Thanked 3 Times in 3 Posts
Smile

Quote:
why don't you ditch the DetailsView and simply use the HyperLink and image controls directly
How I can bind the hyperlink and image controls collectively with the single picture? how I apply datasource property.
I want to assign LargeImageUrl property to HyperLink's NavigateUrl property and SmallImageUrl property to Image's ImageUrl property for a single Picture (First picture for every selected album).

please give example...
Reply With Quote
  #6 (permalink)  
Old July 30th, 2012, 03:23 PM
Imar's Avatar
Wrox Author
Points: 72,055, Level: 100
Points: 72,055, Level: 100 Points: 72,055, Level: 100 Points: 72,055, Level: 100
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2003
Location: Utrecht, Netherlands.
Posts: 17,086
Thanks: 80
Thanked 1,587 Times in 1,563 Posts
Default

Just do it in code behind. E.g.

myImage.ImageUrl = myPictureSmallIImageUrl;

Where myPicture is a single picture, not a list...

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!
Reply With Quote
  #7 (permalink)  
Old July 31st, 2012, 02:19 PM
Friend of Wrox
Points: 1,469, Level: 15
Points: 1,469, Level: 15 Points: 1,469, Level: 15 Points: 1,469, Level: 15
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Oct 2009
Posts: 341
Thanks: 14
Thanked 3 Times in 3 Posts
Smile

Quote:
myImage.ImageUrl = myPictureSmallIImageUrl;
Thanks, it is working. Actually I used such code many months ago but did not remember. You made it recall again, Thank you.

Quote:
And what is the result you're getting?
By using simple html tags <a> and <img> I am writing this code manually (notice rev property with its value started by ../)

Code:
<a href="../images/bigimage1" rel="zoom-id:hyperlink2;" rev="../images/mediumimage1"><img src="../images/smallimage1"/></a>
But when I wanted to automate this procedure by using repeater then this functionality breaks
Code:
<asp:Repeater ID="Repeater1" runat="server" DataSourceID="EntityDataSource1">
            <ItemTemplate>
                <asp:HyperLink runat="server" NavigateUrl='<%# Eval("LargeImageUrl") %>' rel="zoom-id:HyperLink2" rev='<%# Eval("MediumImageUrl") %>'><asp:Image ID="Image1" runat="server" ImageUrl='<%# Eval("SmallImageUrl") %>' /></asp:HyperLink>
            </ItemTemplate>
            </asp:Repeater>
As I don't see rev property for server control HyperLink so I manually wrote it. When parsed and I saw the source code of page then it was different than the html controls code. It generates the below code...

Code:
<a id="ContentPlaceHolder1_Repeater1_HyperLink1_0" href="../images/bigimage1" rel="zoom-id:hyperlink2;" rev="~/images/mediumimage1"><img src="../images/smallimage1"/></a>
Now again notice rev property, it starts with ~/, which is getting me error. I want it to be started from ../ (../../ according folder structure).

So how I can manipulate rev property and fix this problem.

Many Thanks
Reply With Quote
  #8 (permalink)  
Old August 2nd, 2012, 03:34 AM
Imar's Avatar
Wrox Author
Points: 72,055, Level: 100
Points: 72,055, Level: 100 Points: 72,055, Level: 100 Points: 72,055, Level: 100
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2003
Location: Utrecht, Netherlands.
Posts: 17,086
Thanks: 80
Thanked 1,587 Times in 1,563 Posts
Default

Hi there,

Since rev is not a known property, the path you assign to it is not converted for you. A few solutions:

1. Don't use ~/ but use / as that's a plain client URL

2. Use ResolveUrl() to convert the ~ to the proper root path.

3. In code behind hook into each item, and add the rev attribute to the control's Attributes collection.

All of this is a bit too off-topic for the book's forum category so if you have follow up questions, please start a new thread in an appropriate category: http://p2p.wrox.com/asp-net-4-539/

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!
Reply With Quote
  #9 (permalink)  
Old August 2nd, 2012, 02:42 PM
Friend of Wrox
Points: 1,469, Level: 15
Points: 1,469, Level: 15 Points: 1,469, Level: 15 Points: 1,469, Level: 15
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Oct 2009
Posts: 341
Thanks: 14
Thanked 3 Times in 3 Posts
Smile

Thanks Imar,
for temporarily I have used another field AlternateImageUrl and assigning values started from ../

I will later on go to 2nd or 3rd option you have suggested.

Thanks once again
Reply With Quote
Reply


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
Photo Album Questions m3ben BOOK: ASP.NET 2.0 Instant Results ISBN: 978-0-471-74951-6 1 April 4th, 2007 12:12 PM
paging in photo album xperre BOOK: ASP.NET 2.0 Instant Results ISBN: 978-0-471-74951-6 1 April 2nd, 2007 03:32 PM
Wrox Photo Album Help rsearing BOOK: ASP.NET 2.0 Instant Results ISBN: 978-0-471-74951-6 6 September 27th, 2006 02:30 PM
Photo Album Menus Tremmorkeep BOOK: ASP.NET 2.0 Instant Results ISBN: 978-0-471-74951-6 1 August 15th, 2006 01:49 PM
OLE picture - accessing the picture property bdcrisp Excel VBA 0 December 7th, 2003 09:35 PM



All times are GMT -4. The time now is 06:27 AM.


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