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.