Wrox Programmer Forums
|
BOOK: ASP.NET 2.0 Instant Results ISBN: 978-0-471-74951-6
This is the forum to discuss the Wrox book ASP.NET 2.0 Instant Results by Imar Spaanjaars, Paul Wilton, Shawn Livermore; ISBN: 9780471749516
Welcome to the p2p.wrox.com Forums.

You are currently viewing the BOOK: ASP.NET 2.0 Instant Results ISBN: 978-0-471-74951-6 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 22nd, 2007, 06:13 AM
Authorized User
 
Join Date: Feb 2007
Posts: 15
Thanks: 0
Thanked 0 Times in 0 Posts
Default Chapter 9 WebShop / Shop Default Page

Hello, I'm having a lot of trouble trying to change the Shop/Default.aspx page to list the product categoies in a dropdown menu rather than the current repeater control. The second problem I'm having is getting the Dataset to display the correct category based on the selected index change from the dropdown list control rather than the repeater.

Can you show me how to change the page and / or page code behind to use a dropdown list rather than the default repeater for this page?

Thanks for your help.

Robert

 
Old February 22nd, 2007, 05:16 PM
Imar's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
Default

Hi Rob,

This should be easy to do. First delete all code related to the Repeater. Then add a drop down, open its Task Pane and bind it to an ObjectDataSource. You could reuse ObjectDataSource1 or create a brand new one. You should get the option to specify the DataValueField and the DataTextField.

Then write an event handler for the SelectedIndexCHanged event (basically, just double-click the DDL in Design View) and access the SelectedValue to get the value of the item selected in this list.

Does this help?

Imar
---------------------------------------
Imar Spaanjaars
http://Imar.Spaanjaars.Com
Everyone is unique, except for me.
Author of ASP.NET 2.0 Instant Results and Beginning Dreamweaver MX / MX 2004
Want to be my colleague? Then check out this post.
 
Old February 23rd, 2007, 12:55 AM
Authorized User
 
Join Date: Feb 2007
Posts: 15
Thanks: 0
Thanked 0 Times in 0 Posts
Default

A little bit. I'm still having trouble writting the event handler. Can you point to me to an example or show me what this should look like?

Also having problem with creating an edit or update product form. Will it be easier to create a separate page for this or to add it to the current products page in the management folder?

And you said earlier to look at Chapter 5 to find an example of how to write the code for the product update, but can you give me a specific section or page numbers to look at?

Thanks for the help, I think I may be making this harder than it needs to be, but I'm still a bit confused as to how all the parts are working together with this three tiered structure.

Robert

 
Old February 24th, 2007, 06:53 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 Robert,

Sure. Here's what you can do:

1. Add a DropDownList to the page.

2. Set its AutoPostBack property to True.

3. Double click the control in Design View to set up the handler.

In the markup you should end up with this code:
Code:
<asp:DropDownList ID="DropDownList1" runat="server" AutoPostBack="True">
</asp:DropDownList>
The AutoPostBack property ensures that whenever the users selects a new item in the list, the page posts back to the server where it will trigger its SelectedIndexChanged event. The event handler, set up when you double clicked the control looks like this:
Code:
Protected Sub DropDownList1_SelectedIndexChanged( _
    ByVal sender As Object, ByVal e As System.EventArgs) _
    Handles DropDownList1.SelectedIndexChanged

End Sub
Inside this event handler, you can get the current value of the DropDownList like this:

Dim selectedValue As String = DropDownList1.SelectedValue

From there, you can do with selectedValue whatever it is you need to do.

Can you define "having problem with creating an edit or update product form"? Usually, I created separate pages for tasks like Add/Edit. For example, the CMS chapter has a ContentList.aspx page that lists all content items and an AddEditContent.aspx page used to add and edit content items.

The entire CMS chapter is about managing content in a web site, so you may want to browse through the entire chapter to get a general understanding of the concepts. Then turn to the section Managing Content (page 153 - 159) to get a detailed examination of how you can add and edit content items.

You may also want to read these two articles:

http://imar.spaanjaars.com/QuickDocId.aspx?quickdoc=416
http://imar.spaanjaars.com/QuickDocId.aspx?quickdoc=419

to get a better understanding of multi layered design. The concepts used in the book and explained in the article have a lot of similarities that may help you better understand the book.

I am currently working on part three which I am hoping to publish this weekend.

Imar
---------------------------------------
Imar Spaanjaars
http://Imar.Spaanjaars.Com
Everyone is unique, except for me.
Author of ASP.NET 2.0 Instant Results and Beginning Dreamweaver MX / MX 2004
Want to be my colleague? Then check out this post.
 
Old February 27th, 2007, 12:44 PM
Authorized User
 
Join Date: Feb 2007
Posts: 15
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Hello Imar, thanks for the tutorial links in the last reply. I’ve read them all now and have a much better understanding of how everything is fitting together. They're a great help. However, do to my limited experience with programming and after following your instructions I’m still having one problem.

I can get the dropdown list to auto post back ok, and set the selected value in code behind, but nothing happens to the products listed in the datalist. This list defaults to the first category, but won’t change when I select a new category form the dropdownlist. Is the problem in the ShopManager, ShopManagerDB, or the Code behind for the Shop/Default.aspx page itself? I’ve got the Selected value but what do I need to do with it, or what needs to receive it?

Also I’ve started reading and working with the CMS chapter five site, but continue to get this error when attempting to access an admin link “manage content”. No problem with admin login, and the other admin pages, just this one page. See the error here;

Compilation Error
Description: An error occurred during the compilation of a resource required to service this request. Please review the following specific error details and modify your source code appropriately.

Compiler Error Message: ASPNET: Make sure that the class defined in this code file matches the 'inherits' attribute, and that it extends the correct base class (e.g. Page or UserControl).

Source Error:

__________________________________________________ _______
Line 5: ' Visit p2p.wrox.com to discuss this code in the Wrox forums.
Line 6:
Line 7: Partial Class ContentList
Line 8: Inherits System.Web.UI.Page
Line 9:

Source File: C:\Inetpub\wwwroot\Cms\Management\ContentList.aspx .vb Line: 7
__________________________________________________ _______________

I’m looking on the forum for the answer to this problem, but still haven’t found it. Can you please direct me again to the fix?

Thanks again for all your help.

Robert


 
Old February 27th, 2007, 01:19 PM
Imar's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
Default

Quote:
quote:I’ve got the Selected value but what do I need to do with it, or what needs to receive it?
You need to feed it to the code that receives it now as well.

I don't have access to the book's code right now, but if I recall correctly, the page uses the QueryString to determine the category, right? I think it uses an ODS or a SDS set up to use a QueryString parameter. In your case, you should probably replace that with a generic <Parameter>, set its value in Code Behind and then rebind.
This requires quite some code, but it's difficult for me to tell you what to do exactly as I don't know how your current code looks like. Maybe you can post it on-line somewhere or zip it up and send it to me?

The other problem may have to do with how the pages in the Management folder are named. They are called ContentList for example. However, there is already a ContentList page in the root so you may get this error. Others reported this too, but I have never been able to fully reproduce it. To fix it, give each page in /Management a unique name, e.g.:

Partial Class Management_ContentList

Don't forget to change the <% Page directive in the code before as well.

Cheers,

Imar
 
Old February 28th, 2007, 01:11 AM
Authorized User
 
Join Date: Feb 2007
Posts: 15
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Thanks Imar, I got the CMS site to work now.:) The problem was within the partial class name being the same as the other page with the same class name. I didn't need to change the name of the pages just the partial class name and then changed the "inherits" link in the page directive. That fixed it. I noticed this only happens with sites that I've installed to the default IIS folder, the ones I'm running from the Visual Studio 2005 directory seem to work fine with two partial classes of the same name but within different sub directories. Hum??

As for the other problem of getting the dropdownlist to work with the webshop site. I'd be happy if you could look at the code. Where should I send the zip file to?

Robert

 
Old February 28th, 2007, 04:04 AM
Imar's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
Default

Yeah, correct. Only the class names need to be fixed. Pages already have a unique name because they live in separate folders. My explanation wasn't very clear on this; my intention was to tell you to change the class names, not the page names.... ;)

Send me a message through my profile page. I'll reply, so you have my real e-mail address.

Cheers,

Imar
---------------------------------------
Imar Spaanjaars
http://Imar.Spaanjaars.Com
Everyone is unique, except for me.
Author of ASP.NET 2.0 Instant Results and Beginning Dreamweaver MX / MX 2004
Want to be my colleague? Then check out this post.
 
Old March 1st, 2007, 05:27 PM
Imar's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
Default

For anyone else interested in a solution: here's the fix. First, add a DDL to the markup of the page.
Code:
<asp:DropDownList ID="DropDownList1" runat="server" DataSourceID="ObjectDataSource1"
  AppendDataBoundItems="True" AutoPostBack="True" DataTextField="Description" DataValueField="Id">
</asp:DropDownList>
Next, add an ODS to get items for the list:
Code:
<asp:ObjectDataSource ID="ObjectDataSource1" runat="server" SelectMethod="GetProductCategories" 
    TypeName="ShopManager">
</asp:ObjectDataSource>
Finally, add the following code for the SelectedIndexChanged event of the DDL:
Code:
Protected Sub DropDownList1_SelectedIndexChanged( _
    ByVal sender As Object, ByVal e As System.EventArgs) _
    Handles DropDownList1.SelectedIndexChanged
  categoryId = DropDownList1.SelectedValue
  LoadData()
End Sub
This code sets the private categoryId variable to the value from the drop down and then calls LoadData to rebind the list with products.

Cheers,

Imar
---------------------------------------
Imar Spaanjaars
http://Imar.Spaanjaars.Com
Everyone is unique, except for me.
Author of ASP.NET 2.0 Instant Results and Beginning Dreamweaver MX / MX 2004
Want to be my colleague? Then check out this post.
 
Old March 11th, 2007, 03:16 AM
Authorized User
 
Join Date: Feb 2007
Posts: 15
Thanks: 0
Thanked 0 Times in 0 Posts
Default

It never seems to be that easy. I just noticed that when I click the next page or previous page links for viewing products in categories that have more than four products the page reloads to the first category of products. How can we get the page to reload to the current selected DDL value when using these links to stay within the same categoy and see additional products within the same category?






Similar Threads
Thread Thread Starter Forum Replies Last Post
Chapter 8, shop Beowulf BOOK: PHP and MySQL: Create-Modify-Reuse ISBN: 978-0-470-19242-9 3 September 30th, 2010 03:59 PM
Where is the default.aspx in chapter 1? jkacher BOOK: ASP.NET 2.0 Instant Results ISBN: 978-0-471-74951-6 1 February 29th, 2008 02:30 PM
Chapter 6 error: Parameter.. .has no default value ikaminow BOOK: Beginning VB.NET Databases 1 July 27th, 2007 07:39 AM
redirect to page other than default page sarah lee ASP.NET 1.0 and 1.1 Basics 3 December 15th, 2006 05:45 PM
Problems in Chapter 2 - Default.aspx nduckste BOOK: ASP.NET 2.0 Website Programming Problem Design Solution ISBN: 978-0-7645-8464-0 7 October 30th, 2006 11:50 PM





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