Wrox Programmer Forums
|
BOOK: ASP.NET 2.0 Website Programming Problem Design Solution ISBN: 978-0-7645-8464-0
This is the forum to discuss the Wrox book ASP.NET 2.0 Website Programming: Problem - Design - Solution by Marco Bellinaso; ISBN: 9780764584640
Welcome to the p2p.wrox.com Forums.

You are currently viewing the BOOK: ASP.NET 2.0 Website Programming Problem Design Solution ISBN: 978-0-7645-8464-0 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 September 12th, 2007, 04:09 AM
Friend of Wrox
 
Join Date: Sep 2003
Posts: 143
Thanks: 0
Thanked 1 Time in 1 Post
Default Chapter 5 - AddEditArticles

Anyone else had any trouble with this?

I forgot to properly debug stuff before, so today I decided to give this page a go. Immediately, i got greeted with errors.

The first error was because I somehow ended up putting the objDataSources in wrong. With that corrected, I still got errors, mostly related to the ddlCountries control.

I got an error stating that there still was somethign wrong with the odjDataSource of ddlCountries. I checked my code against the downloaded code, but it seemed similar.

I solved it by commenting out the SelectParameters of the odjDataSource in objAllCountries.

I then got an error stating that System.String does not have a value property. I solved that by removing the bold statements from the code below:

<asp:TemplateField HeaderText="Country" SortExpression="Country">
  <ItemTemplate>
    <asp:Label ID="lblCountry" runat="server" Text='<%# Eval
      ("Country") %>'></asp:Label>
  </ItemTemplate>
  <EditItemTemplate>
    <asp:DropDownList ID="ddlCountries" runat="server"
      DataTextField="Value" DataValueField="Key"
      DataSourceID="objAllCountries"
      SelectedValue='<%# Bind("Country") %>' Width="100%" />
  </EditItemTemplate>
  </asp:TemplateField>

What's weird is that this came straight from Marco's code, and the SelectParameter is even documented in the book. Yet, I have not seen this in the errata or found a link anywhere else on the forum...

Anyone experienced similar trouble?

Thanks.

http://entropia-online.blogspot.com/
__________________
http://entropia-online.blogspot.com/
 
Old September 12th, 2007, 07:35 AM
Friend of Wrox
 
Join Date: Mar 2007
Posts: 488
Thanks: 2
Thanked 11 Times in 10 Posts
Default

Peter,

I haven't touched this code, so it should be the same as what you started out with. Here's what i have for the objAllCountries:

   <asp:ObjectDataSource ID="objAllCategories" runat="server" SelectMethod="GetCategories"
      TypeName="MB.TheBeerHouse.BLL.Articles.Category"></asp:ObjectDataSource>
   <asp:ObjectDataSource ID="objAllCountries" runat="server" SelectMethod="GetCountries"
      TypeName="MB.TheBeerHouse.Helpers">
      <SelectParameters>
         <asp:Parameter DefaultValue="true" Name="insertEmpty" Type="Boolean" />
      </SelectParameters>
   </asp:ObjectDataSource>

and for the templatefield:

         <asp:TemplateField HeaderText="Country" SortExpression="Country">
            <ItemTemplate>
               <asp:Label ID="lblCountry" runat="server" Text='<%# Eval("Country") %>'></asp:Label>
            </ItemTemplate>
            <EditItemTemplate>
               <asp:DropDownList ID="ddlCountries" runat="server" DataTextField="Value" DataValueField="Key"
                  DataSourceID="objAllCountries" SelectedValue='<%# Bind("Country") %>' Width="100%" />
            </EditItemTemplate>
         </asp:TemplateField>

Not sure what to suggest, other than trying what i've pasted (i nkow you prolly have before anyway, but you never know!!)



jimi

http://www.originaltalent.com
 
Old September 12th, 2007, 09:05 AM
Friend of Wrox
 
Join Date: Sep 2003
Posts: 143
Thanks: 0
Thanked 1 Time in 1 Post
Default

Hi Jimi,

That is exactly the same code I used, and that didn't work for me.

I got an error saying that GetCountries did not have an overload where the insertEmpty could be used. Something along those lines. Once that was removed, it then complained that String didn't have a values property (the GetCountries loads a StringCollection).

Very weird...

I did spot a bunch of other errors on various page (mostly due to typos on my behalf), but this doesn't really seem related to any typos...

http://entropia-online.blogspot.com/
 
Old September 12th, 2007, 09:19 AM
Friend of Wrox
 
Join Date: Mar 2007
Posts: 488
Thanks: 2
Thanked 11 Times in 10 Posts
Default

Peter,

Do you have these overloads in your Helpers.cs class:

        public static StringCollection GetCountries()
        {
            StringCollection countries = new StringCollection();
            countries.AddRange(_countries);
            return countries;
        }
        public static SortedList GetCountries(bool insertEmpty)
        {
            SortedList countries = new SortedList();
            if (insertEmpty)
                countries.Add("", "Please select one...");
            foreach (String country in _countries)
                countries.Add(country, country);
            return countries;
        }

clutching at straws here i suppose...

jimi

http://www.originaltalent.com
 
Old September 12th, 2007, 10:24 AM
Friend of Wrox
 
Join Date: Sep 2003
Posts: 143
Thanks: 0
Thanked 1 Time in 1 Post
Default

OMG. I did not have that :(

I just found it in the source code of the original :( I actually will admit I seriously dislike how some of the code is left out, and we have to scramble to find it ourselves.

I was wondering before how the "Please select one..." was added to the list of countries. I also found there was an undocumented addition to the Page_Load event, which switches the labels around.

I also fixed a few other things, but still have a problem when trying to update. The stored procedure fires fine, but the ArticleID parameter it gets is 0 for some reason.

edit: Think I found the problem. Can't test now though, heading to Holland to see The Police :)

Thanks (again) jimi. You just saved me a lot of frustration :)

http://entropia-online.blogspot.com/
 
Old September 12th, 2007, 10:58 AM
Friend of Wrox
 
Join Date: Mar 2007
Posts: 488
Thanks: 2
Thanked 11 Times in 10 Posts
Default

do do do - da da da

jimi

http://www.originaltalent.com
 
Old September 12th, 2007, 11:11 AM
Friend of Wrox
 
Join Date: Mar 2007
Posts: 488
Thanks: 2
Thanked 11 Times in 10 Posts
Default

Peter,

As an aside. altho' the countries don't change that much :), you might be advised to grab an xml definition of the counties and work from that, the rationale being that future changes wouldn't require a recompile should angola change it's name to alogna etc... (merely an update of your countries.xml doc).

edit: here's quite a 'nice' countries.xml file

http://www.dbis.informatik.uni-goettingen.de/Mondial/Mondial-Distributed/countries.xml

however, as a priority, i'd put it way down as a 9.75 as it sounds like you've got quite a lot more pressing issues on your plate at the moment!!! (i know the feeling!)

ok -later

jimi

http://www.originaltalent.com
 
Old September 16th, 2007, 10:51 AM
Friend of Wrox
 
Join Date: Sep 2003
Posts: 143
Thanks: 0
Thanked 1 Time in 1 Post
Default

Hi Jimi,

I actually pondered stripping the country bit etc out of the code completely. I've long had the idea of building numerous websites for numerous clients, and it seems silly to me to duplicate so much code.

Instead, I'll most likely end up creating one master database where I keep stuff like countries (most likely using the ISO list), etc. In fact, the idea crossed my mind to also store regional information there (zipcodes etc, so whenever someone signs up they only have to enter their zipcode and the rest of their address would be automatically filled in. There's all kinds of catches to that, but my guess is that if you get a few customers from the same region, having them share the costs of implementation might make it a worthwhile addition to increase user experience).

The massive benefit of this approach would be that if anything changes, it still is stored centrally, and changes could be picked up overnight without requirring recompilation of code, etc.

But like you stated, that'd be low priority, unless I suddenly find myself buried kneedeep in clients, and able to start working as my own boss fulltime ;)

Till then, I'll keep dreamin'.

The Police rocked, by the way ;)

Peter

http://entropia-online.blogspot.com/





Similar Threads
Thread Thread Starter Forum Replies Last Post
Chapter 2 - End of chapter exercises whizzkid1892 BOOK: Beginning PHP5, Apache, and MySQL Web Development ISBN: 978-0-7645-7966-0 1 July 30th, 2008 12:02 PM
Couple Errors on AddEditArticles page pinch BOOK: ASP.NET 2.0 Website Programming Problem Design Solution ISBN: 978-0-7645-8464-0 13 December 14th, 2007 04:01 AM
Generics chapter 12 difficult chapter i found ...? Larryz C# 2005 1 July 4th, 2007 09:40 PM





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