 |
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
|
|
|
|
|

April 14th, 2010, 03:34 AM
|
|
Friend of Wrox
|
|
Join Date: Oct 2009
Posts: 341
Thanks: 14
Thanked 3 Times in 3 Posts
|
|
Dropdown list in photo album
As in the book I am using the dropdown list in photo album (Default.aspx)
Code:
<asp:DropDownList ID="DropDownList1" runat="server" AutoPostBack="True"
DataSourceID="LinqDataSource1" DataTextField="Name" DataValueField="Id"
Width="129px">
<asp:ListItem Value="">Please Choose Album</asp:ListItem>
</asp:DropDownList>
And LinqDataSource1 is defines as follows
Code:
<asp:LinqDataSource ID="LinqDataSource1" runat="server" ContextTypeName="JackGenieDataContext" Select="new (Id, Name)"
TableName="PhotoAlbums">
</asp:LinqDataSource>
But when I see it in browser then it does not show this option and directly fills it up with the available albums and shows the first album in list (sonic youth for instance).
Where does go the Please Choose Album. have I made some mistake?
thank you.
|
|

April 14th, 2010, 03:43 AM
|
 |
Wrox Author
|
|
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
|
|
The book doesn't haven't a "Please choose an album" option, does it? So I am not sure what exactly you're asking....
Imar
|
|

April 14th, 2010, 03:59 AM
|
|
Friend of Wrox
|
|
Join Date: Oct 2009
Posts: 341
Thanks: 14
Thanked 3 Times in 3 Posts
|
|
I am saying that as you have a dropdown list in Reviews.aspx to filter the reviews based on specific genre but also have an option something like "Please choose Genre", likewise I am trying to add such option "Please choose Photo Album" in Default.aspx for Photo albums. But here you use the Linqdata Source so I am not getting that option "Please choose Photo Album" in the browser.
Hence I just wanna ask that how I can add such option in case of LinqData Source.
Thank you.
|
|

April 14th, 2010, 04:09 AM
|
 |
Wrox Author
|
|
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
|
|
Ah, that helps. being specific makes it easier for me to help you.
AppendDataBoundItems="True" is the key.....
Imar
|
|

April 14th, 2010, 04:20 AM
|
|
Friend of Wrox
|
|
Join Date: Oct 2009
Posts: 341
Thanks: 14
Thanked 3 Times in 3 Posts
|
|
Hello, as soon as I added the AppendDataBoundItems then an error was generated.
Code:
Operator '==' incompatible with operand types 'Int32' and 'Object'
Dropdown list is as follows
Code:
<asp:DropDownList ID="DropDownList1" runat="server" AutoPostBack="True" AppendDataBoundItems="true"
DataSourceID="LinqDataSource1" DataTextField="Name" DataValueField="Id"
Width="129px">
<asp:ListItem Value="">Please Choose Album</asp:ListItem>
</asp:DropDownList>
And Data source is as follows.
Code:
<asp:LinqDataSource ID="LinqDataSource1" runat="server" ContextTypeName="SiteDataContext" Select="new (Id, Name)"
TableName="PhotoAlbums">
</asp:LinqDataSource>
I am using same table structure as in the book.
What has gone wrong now? As it was not giving any error without AppendDataBoundItems.
|
|

April 14th, 2010, 11:19 AM
|
 |
Wrox Author
|
|
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
|
|
You could set a default value of an ID that doesn't exist in the database, like -1, to the Value of the ListItem. Cheesy, but t works...
Imar
|
|

April 14th, 2010, 02:40 PM
|
|
Friend of Wrox
|
|
Join Date: Oct 2009
Posts: 341
Thanks: 14
Thanked 3 Times in 3 Posts
|
|
hello,
I did set the value to -1 but it got me other error.
I used the code as follows
Code:
<asp:DropDownList ID="DropDownList1" runat="server" AutoPostBack="True" AppendDataBoundItems="true"
DataSourceID="LinqDataSource1" DataTextField="Name" DataValueField="Id"
Width="129px">
<asp:ListItem Value="-1">Please Choose Album</asp:ListItem>
</asp:DropDownList>
And the error was
Code:
Sequence contains no elements
Line 21: Using myDatabaseContext As JackGenieDataContext = New JackGenieDataContext()
Line 22:
Line 23: Dim photoAlbumOwner As String = (From p In myDatabaseContext.PhotoAlbums _
Line 24: Where p.Id = photoAlbumId _
Line 25: Select p.UserName).Single()
|
|

April 14th, 2010, 03:14 PM
|
 |
Wrox Author
|
|
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
|
|
Try SingleOrDefault instead of just Single. When there's no matching record, SingleOrDefault will return null / Nothing. You can check for that value, and skip remaining code when the item is null.
Cheers,
Imar
|
|

April 14th, 2010, 03:24 PM
|
|
Friend of Wrox
|
|
Join Date: Oct 2009
Posts: 341
Thanks: 14
Thanked 3 Times in 3 Posts
|
|
Thanks working now.
but also shows the EmptyDataTemplate (that is, album does not has any photos in it) with "Please Choose Album" option which is set for list view
Code:
<EmptyDataTemplate>
Sorry,Album Has No Any Photos In It.
</EmptyDataTemplate>
It does not make sense to see this message with Please Choose Album.
|
|

April 14th, 2010, 03:29 PM
|
 |
Wrox Author
|
|
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
|
|
You can set the Visible property of the list control to False if the item is Nothing...
Imar
|
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 |
| Error posting photo to photo album |
abel714 |
BOOK: ASP.NET 2.0 Instant Results ISBN: 978-0-471-74951-6 |
10 |
February 5th, 2007 03:07 AM |
| 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 |
|
 |