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 March 1st, 2009, 01:10 PM
Authorized User
 
Join Date: Nov 2008
Posts: 12
Thanks: 4
Thanked 0 Times in 0 Posts
Send a message via Yahoo to Rambo
Default Object data source control

Hello,
I have a serious problem please help.
I'm currently reading chapter five, I'm reached the solution section , I'm implement all the code myself in order to gain hands-on experience.
my problem as follows , when I wrote the .aspx code for the page ManageCategories.aspx things did not goes well, even I checked the code many times and compared it to the code download for this book the later worked and the first does not ! and the problem particularly with update categories and delete categories processes, thankfully I do not have problems with insert categories every time I try to update category I get this error as pictured here:
http://rapidshare.com/files/20405988..._code.rar.html
and every time I try to delete category I get an error similar to the first one
http://rapidshare.com/files/20405988..._code.rar.html
I tried every possible solution, at the first glance, I thought it is because the order of the details view fields so I re-ordered the fields to match the parameters order in the MB.TheBeerHouse.Articles.Category's UpdateCategory static method but unfortunately it did not changed any thing.
Another try I did, I set break point on MB.TheBeerHouse.Articles.Category's UpdateCategory method, I spotted that the execution do not reach this method !, although the logic of the program as follows:
1.The objCurrentCategory control call the UpdateCategory method of it's type MB.TheBeerHouse.Articles.Category and it assumed to pass in DataKeyNames field of the current record,title field, importance field, imageurl field, and description field.
2.The Updatecategory method receive the parameters and creates new CategoryDetails to pass it as input parameter to DAL's UpdateCategory.
3. The DAL's UpdateCateogory execute the stored procedure.
I did not wrote this before trying every possible workround, now I gave up please help me.
I'm using Microsoft Visual Studio 2008 professional and I targeted the project to the version 2 of the .Net framework not 3.5 which is the current version and my OS is Windows Vista Ultimate these info might be useful for you.
and here is the ManageCategoires.aspx code:
<%@ Page Language="C#" MasterPageFile="~/Template.master" AutoEventWireup="true" CodeFile="ManagerCategories.aspx.cs" Inherits="MB.TheBeerHouse.UI.Admin_ManagerCategori es" Title="The Beer House- Manager Article Categories" %>
<asp:Content ID="ManagerCategoriesContent" runat="server" ContentPlaceHolderID="MainContent">
<asp:ObjectDataSource ID="objAllCategories" runat="server" TypeName="MB.TheBeerHouse.BLL.Articles.Category"
SelectMethod="GetCategories" DeleteMethod="DeleteCategory" />
<div class="sectiontitle">Manage Article Categoires</div>
<p></p>
<asp:GridView ID="gvwCategories" runat="server" DataSourceID="objAllCategories" AutoGenerateColumns="false"
DataKeyNames="ID" onrowcreated="gvwCategories_RowCreated"
onrowdeleted="gvwCategories_RowDeleted"
onselectedindexchanged="gvwCategories_SelectedInde xChanged" Width="100%"
ShowHeader="False">
<Columns>
<asp:ImageField DataImageUrlField="ImageUrl">
<ItemStyle Width="100px" />
</asp:ImageField>
<asp:TemplateField>
<ItemTemplate>
<div class="sectionsubtitle">
<asp:Literal ID="lblCatTitle" runat="server" Text='<%# Eval("Title") %>' />
</div>
<br />
<asp:Literal ID="lblCatDescription" runat="server" Text='<%# Eval("Description") %>' />
</ItemTemplate>
</asp:TemplateField>

<asp:HyperLinkField Text="<img border='0' src='../Images/ArrowR.gif' alt='View Articles' />" DataNavigateUrlFields="ID" DataNavigateUrlFormatString="ManageArticles.aspx?I D={0}">
<ItemStyle HorizontalAlign="Center" Width="20px" />
</asp:HyperLinkField>
<asp:CommandField ButtonType="Image" SelectImageUrl="~/Images/Edit.gif" SelectText="Update Category" ShowSelectButton="true">
<ItemStyle HorizontalAlign="Center" Width="20px" />
</asp:CommandField>
<asp:CommandField ButtonType="Image" DeleteImageUrl="~/Images/Delete.gif" DeleteText="Delete Category" ShowDeleteButton="true" >
<ItemStyle HorizontalAlign="Center" Width="20px" />
</asp:CommandField>
</Columns>
<EmptyDataTemplate><b>No categories to show</b></EmptyDataTemplate>
</asp:GridView>
<asp:ObjectDataSource ID="objCurrentCategory" runat="server" TypeName="MB.TheBeerHouse.BLL.Articles.Category" InsertMethod="InsertCategory" SelectMethod="GetCategoryByID" UpdateMethod="UpdateCategory">
<SelectParameters>
<asp:ControlParameter ControlID="gvwCategories" Name="categoryID"
PropertyName="SelectedValue" Type="Int32" />
</SelectParameters>
</asp:ObjectDataSource>
<p></p>
<asp:DetailsView ID="dvwCategory" runat="server" AutoGenerateRows="False"
AutoGenerateInsertButton="True" AutoGenerateEditButton="True"
DataSourceID="objCurrentCategory" Width="50%" Height="50px"
HeaderText="Category Details" DefaultMode="Insert"
onitemcommand="dvwCategory_ItemCommand" onitemcreated="dvwCategory_ItemCreated"
oniteminserted="dvwCategory_ItemInserted"
onitemupdated="dvwCategory_ItemUpdated" DataKeyNames="ID">
<FieldHeaderStyle Width="100px" />
<Fields>
<asp:BoundField HeaderText="ID" DataField="ID" ReadOnly="true" InsertVisible="false" SortExpression="ID" />
<asp:BoundField HeaderText="Added Date" DataField="AddedDate" InsertVisible="false" SortExpression="AddedDate" ReadOnly="true" />
<asp:BoundField HeaderText="Added By" DataField="AddedBy" ReadOnly="true" InsertVisible="false" SortExpression="AddedBy" />
<asp:TemplateField HeaderText="Title" SortExpression="Title">
<ItemTemplate>
<asp:Label ID="lblTitle" runat="server" Text='<%# Eval("Title") %>' Width="100%" />
</ItemTemplate>
<EditItemTemplate>
<asp:TextBox ID="txtTitle" runat="server" Text='<%# Bind("Title") %>' MaxLength="256" Width="100%" />
<asp:RequiredFieldValidator ID="requireTitle" runat="server" ControlToValidate="txtTitle" SetFocusOnError="true" ErrorMessage="Title field is required" ToolTip="Title field is required" Display="Dynamic" />
</EditItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Importance" SortExpression="Importance">
<ItemTemplate>
<asp:Label ID="lblImportance" runat="server" Text='<%# Eval("Importance") %>' Width="100%" />
</ItemTemplate>
<EditItemTemplate>
<asp:TextBox ID="txtImportance" runat="server" Text='<%# Bind("Importance") %>' MaxLength="256" Width="100%" />
<asp:RequiredFieldValidator ID="requireImportance" runat="server" ControlToValidate="txtImportance" SetFocusOnError="true" ErrorMessage="Importance field is required" ToolTip="Importance field is required" Display="Dynamic" />
<asp:CompareValidator ID="chkImportance" runat="server" ControlToValidate="txtImportance" Operator="DataTypeCheck" Type="Integer" SetFocusOnError="true" ErrorMessage="Importance must be valid integer" ToolTip="Importance must be valid integer" Display="Dynamic" />
</EditItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Description" SortExpression="Description" ConvertEmptyStringToNull="false">
<ItemTemplate>
<asp:Label ID="lblDescription" runat="server" Text='<%# Eval("Description") %>' Width="100%" />
</ItemTemplate>
<EditItemTemplate>
<asp:TextBox ID="txtDescription" runat="server" Text='<%# Bind("Description") %>' Rows="5" TextMode="MultiLine" MaxLength="4000" Width="100%" />
</EditItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Image" ConvertEmptyStringToNull="false">
<ItemTemplate>
<asp:Image ID="imgImage" runat="server" ImageUrl='<%# Eval("ImageUrl") %>' AlternateText='<%# Eval("Title") %>' Visible='<%# !string.IsNullOrEmpty(DataBinder.Eval(Container.Da taItem,"ImageUrl").ToString()) %>' />
</ItemTemplate>
<EditItemTemplate>
<asp:TextBox ID="txtImageUrl" runat="server" Text='<%# Bind("ImageUrl") %>' MaxLength="256" Width="100%" />
</EditItemTemplate>
</asp:TemplateField>
</Fields>
</asp:DetailsView>
</asp:Content>
and here is my UpdateCategory method code:
/// <summary>
/// Updates an existing category
/// </summary>
public static bool UpdateCategory(int categoryID, string title, int importance, string description, string imageUrl)
{
CategoryDetails record = new CategoryDetails(categoryID, DateTime.Now, "", title, description, importance, imageUrl);
bool ret = SiteProvider.Articles.UpdateCategory(record);
BizObject.PurgeCacheItems("articles_Categor");
return ret;
finally here is the DeleteCategory method code:
/// <summary>
/// Delete an existing category
/// </summary>
public static bool DeleteCategory(int categoryID)
{
bool ret = SiteProvider.Articles.DeleteCategory(categoryID);
new RecordDeletedEvent("Category", categoryID, null).Raise();
BizObject.PurgeCacheItems("articles_categor");
return ret;

something amazed me that the original code -Download code for this book- do not have nor of Delete parameters or update parameters and it works and mine does not ! please help me.
You can also download the screen-shots for the errors and the above code files.
__________________
John Rambo
 
Old March 1st, 2009, 03:52 PM
Friend of Wrox
Points: 546, Level: 8
Points: 546, Level: 8 Points: 546, Level: 8 Points: 546, Level: 8
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Feb 2009
Posts: 105
Thanks: 3
Thanked 20 Times in 19 Posts
Default

Something I do when I have a working example that I am trying to emulate is to start two instances of Visual Studio. Load the working project in one instance and my project in the other. This allows me to easily switch back and forth between projects, copy and paste code from the working one into my project.

To use this method with your problem I would set a break point in your project and one in the same place in the TBH project then use F5 to run each project up to the break point, from there single step through. You can single step through several lines of code in your project then do the same lines in the TBH project. This should make it very clear where your code and the TBH code go in different directions. It is also a good way to become intimately familiar with what is going on in the code and how the TBH really works.


Give a man a fish and you feed him for a day. Teach a man to fish and you feed him for a lifetime. Happy fishing
The Following 2 Users Say Thank You to Steve S For This Useful Post:
Lee Dumond (March 4th, 2009), Rambo (March 4th, 2009)
 
Old March 4th, 2009, 01:31 PM
Lee Dumond's Avatar
Wrox Author
 
Join Date: Jan 2008
Posts: 923
Thanks: 12
Thanked 166 Times in 162 Posts
Default

Good answer Steve.

My favorite version is: Build a man a fire, and he will be warm for a day... set a man on fire, and he will be warm for the rest of his life. ;-)
__________________
Visit my blog at http://leedumond.com
Follow me on Twitter: http://twitter.com/LeeDumond

Code:
if (this.PostHelpedYou)
{
   ClickThanksButton(); 
}
 
Old March 4th, 2009, 04:34 PM
Authorized User
 
Join Date: Nov 2008
Posts: 12
Thanks: 4
Thanked 0 Times in 0 Posts
Send a message via Yahoo to Rambo
Default I solved it.

Dear Steve S,

Thank you for your valuable advise.

I solved the problem, It was because I named the Category ID parameter categoryID and the control pass it named id, when id named this parameter in both of UpdateCateogory and DeleteCategory methods it worked !.

It's very strange does the parameter named is an issue ?? , anyway it worked !
__________________
John Rambo





Similar Threads
Thread Thread Starter Forum Replies Last Post
Object Data Source class property Colonel Angus ASP.NET 2.0 Professional 5 March 17th, 2008 03:21 PM
Best Data Source Control to Use in ASP.Net 2.0 srotondo ASP.NET 2.0 Basics 2 January 23rd, 2008 05:30 PM
Object Data Source parameters nabeelalkaff BOOK: ASP.NET 2.0 Website Programming Problem Design Solution ISBN: 978-0-7645-8464-0 8 December 10th, 2007 12:34 AM
Object Data Source error shoakat ASP.NET 2.0 Professional 1 June 20th, 2007 05:40 PM
Object Data Source Error abupapa ASP.NET 2.0 Basics 1 June 13th, 2007 05:43 AM





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