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 February 25th, 2009, 06:51 AM
Authorized User
 
Join Date: Jan 2009
Posts: 51
Thanks: 0
Thanked 0 Times in 0 Posts
Default Displaying Data

Using the PlanetWrox website as an example, I have two questions.

First, how do you keep a default value in a list item when appenddatabounditems = "false". I have two drop down lists on the page with the default list item values set to "please select a genre" and "please select a review". When the user selects a genre, the second drop down is populated with the available reviews for that genre. However, I want to keep a default value of "please select a review". I have tried clearing the items when the page is posted back, but the data still gets appended in the second drop down and if i set the appenddatabounditems to false, I lose the default value. Is there any way that I can add the default value each time the page is posted back?

<asp:DropDownListID="DropDownList1"runat="server"AutoPostBack="True"DataSourceID="SqlDataSource1"DataTextField="Genre"DataValueField="Id"AppendDataBoundItems="true">
<asp:ListItemValue="">Please select a genre</asp:ListItem>
</asp:DropDownList>
<asp:SqlDataSourceID="SqlDataSource1"runat="server"ConnectionString="<%$ ConnectionStrings:PlanetWroxConnectionString1 %>"SelectCommand="SELECT [Genre], [Id] FROM [Genre] ORDER BY [Genre]">
</asp:SqlDataSource>
<asp:DropDownListID="DropDownList2"runat="server"DataSourceID="SqlDataSource2"DataTextField="Name"DataValueField="Id"AppendDataBoundItems="true"AutoPostBack="True">
<asp:ListItemValue="">Please select a review</asp:ListItem>
</asp:DropDownList>
<asp:SqlDataSourceID="SqlDataSource2"runat="server"ConnectionString="<%$ ConnectionStrings:PlanetWroxConnectionString1 %>"SelectCommand="SELECT [Name], [GenreId], [Id] FROM [Genre] WHERE ([GenreId] = @GenreId) ORDER BY [Name]">
<SelectParameters>
<asp:ControlParameterControlID="DropDownList1"Name="CountryId"PropertyName="SelectedValue"Type="Int32"/>
</SelectParameters>
</asp:SqlDataSource>

I have tried:

ProtectedSub DropDownList1_SelectedIndexChanged(ByVal sender AsObject, ByVal e As System.EventArgs) Handles DropDownList1.SelectedIndexChanged
If Page.IsPostBack Then
DropDownList2.ClearSelection()
EndIf
EndSub

ProtectedSub DropDownList1_SelectedIndexChanged(ByVal sender AsObject, ByVal e As System.EventArgs) Handles DropDownList1.SelectedIndexChanged
If Page.IsPostBack Then
DropDownList2.AppendDataBoundItems = "false"
EndIf
EndSub

Second, what is the best way to display the review beneath the drop down list once the user selects it? In the book example, there is only one review per item, but I would like to make it so that there can be multiple reviews on one item and when the user selects a review, they can see all the posted reviews beneath it.

I am trying to take the examples one step further in order to gain a true understanding of the concepts provided in the book. Any advice or direction would be greatly appreciated. Thank you.
 
Old February 25th, 2009, 07:00 AM
Imar's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
Default

Hi there,

You can use the Insert method to insert a default item in the Items collection of the DropDownList. For more info: http://imar.spaanjaars.com/QuickDocId.aspx?quickdoc=281

I don't understand your second question. What page is this about? What 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!
 
Old February 25th, 2009, 11:52 AM
Authorized User
 
Join Date: Jan 2009
Posts: 51
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Thank you. I had to work around the insert a little because it kept duplicating the default phrase. So I added this code and it works great:

If Page.IsPostBack Then
DropDownList2.Items.Clear()
DropDownList2.Items.Insert(0,
New ListItem("Please select a genre", ""))
DropDownList2.Visible =
True
EndIf

I guess my second question is two fold. What if, instead of one review for each item, as in the reviews table, there were multiple reviews for the the same item? What is the best way to display those records? For example, a user selects INDIE ROCK from DropDownList1, then DROPDOWNLIST2 appears with several Indie Rock records - Sam's Town, Sonic Youth, Sawdust.

What I would like to know is if I wanted to enter more than one review for Sam's Town by different members and have those different reviews displayed under the DROPDOWNLISTs explained above, what is the best way to display those records?
 
Old February 25th, 2009, 12:00 PM
Imar's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
Default

I still don't get it completely. What page are you talking about? What DropDownList?

If I understand what you're saying you may need another table, like Album (or Record to avoid confusion with the PhotoAlbum table). This table would contain all the record available so users can enter reviews for them. Then when you insert a new review, you follow these steps:

1. Select a Genre

2. Select a Record. If it doesn't exist, you need to create one first

3. Store the review, and store its GenreId and RecordId

Alternatively, you can link Records to Genres so all you need to store in a Review is a RecordId.

Does that help?

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 February 25th, 2009, 12:40 PM
Friend of Wrox
 
Join Date: Feb 2009
Posts: 194
Thanks: 5
Thanked 3 Times in 3 Posts
Default

Do you mean like on Amazon when you view the reviews for a product it has more than one review about the same product listed below it?
 
Old March 25th, 2009, 07:29 AM
Authorized User
 
Join Date: Jan 2009
Posts: 51
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Exactly, Will. I would like the reviews to show up like that. As an added feature, I would like the user to add a review or edit one if they have already posted a review. Any suggestions?
 
Old March 26th, 2009, 11:46 AM
Imar's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
Default

Hi areed24,

In order to support these requirements your Review table needs to save the ID of the item being reviewed, and the User ID. For example:

Review
--------------------
Id
AlbumId
UserId
ReviewText
DateCreated

When you save an Review, you need to store the ID of the Album and the user's ID using Context.User.Identity.Name.

You can now query reviews for a specific Album by querying the Review table with a WHERE clause for the AlbumId. E.g.

SELECT Id, ReviewText FROM Review WHERE AlbumId = 123

Likewise, you can find a Review for a specific user.

To see how to use the User ID in an SqlDataSource, take a look here:

Displaying data based on user logged in

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!
 
Old March 27th, 2009, 08:59 AM
Authorized User
 
Join Date: Jan 2009
Posts: 51
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Thank you, that was very helpful. I am still stuck, however, with the Details View. On the become a contact page, I have a details view with the default mode set to Insert. I would like to preset the userName field with the current logged in user (Profile.Name) and Authorized set to false. How do I have these fields filled when the details view loads? I have tried several events, but nothing seems to work,

<asp:DetailsViewID="DetailsView1"runat="server"AutoGenerateRows="False"
DataKeyNames="Id"DataSourceID="SqlDataSource1"DefaultMode="Insert"Height="50px"Width="125px">
<Fields>
<asp:BoundFieldDataField="Id"HeaderText="Id"InsertVisible="False"ReadOnly="True"SortExpression="Id"/>
<asp:BoundFieldDataField="Name"HeaderText="Name"SortExpression="Name"/>
<asp:BoundFieldDataField="UserId"HeaderText="UserId"SortExpression="UserId"/>
<asp:BoundFieldDataField="Summary"HeaderText="Summary"SortExpression="Summary"/>
<asp:BoundFieldDataField="CityId"HeaderText="CityId"SortExpression="CityId"/>
<asp:CheckBoxFieldDataField="Authorized"HeaderText="Authorized"SortExpression="Authorized"/>
<asp:CommandFieldShowEditButton="True"ShowInsertButton="True"/>
</Fields>
</asp:DetailsView>
 
Old March 27th, 2009, 12:36 PM
Imar's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
Default

Can you define "I have tried several events, but nothing seems to work,"? Do you get an error?

Are you using FindControl to look into the DetailsView and find the relevant contyrols?

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 March 27th, 2009, 01:00 PM
Authorized User
 
Join Date: Jan 2009
Posts: 51
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Nothing happens. To make sure that I had access to the information, I created a label and an event for the page load. When the page loads, the logged in user's name is displayed. I just don't know how to have that information automatically entered into the details view. I am still new to this, and haven't yet heard of the Find Contol. I don't remember that being in the beginning asp.net book.





Similar Threads
Thread Thread Starter Forum Replies Last Post
Displaying My Data jamil umar ASP.NET 2.0 Basics 0 June 5th, 2006 09:48 AM
Displaying data in a table Mike707 Dreamweaver (all versions) 1 April 19th, 2006 01:43 PM
No errors and Data not displaying Calibus Classic ASP Databases 6 August 10th, 2004 08:17 AM
data from query not displaying -Dman100- Classic ASP Professional 8 July 19th, 2004 02:23 AM
Help displaying data in table Calibus Classic ASP Databases 3 July 2nd, 2004 08:40 AM





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