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 December 3rd, 2008, 10:11 PM
Authorized User
 
Join Date: Mar 2008
Posts: 62
Thanks: 1
Thanked 3 Times in 3 Posts
Send a message via Yahoo to kalel_4444
Default Using Gridview to Edit NOT DetailsView ?

Hello all,

I've built some pages that are similar to the /admin/ManageCategories.aspx page where the data list is viewed in a GridView and when clicking the "edit" button it populates in a DetailsView for editing. (this works fine).

Now, I'm trying to change it so that it simply (at least I thought it would be) instead of dropping the data into a DetailsView for editing, it stays in the Grid for editing, but I seem to be having a problem. After updating, the changes don't take effect.

I tried accomplishing this in TBH sample project for testing and I'm having the same problem. Here's the code for the GridView and ObjectDataSource.

Code:
<asp:ObjectDataSource ID="objCategories" runat="server"
        TypeName="TBH.TheBeerHouse.BLL.Articles.Category" 
        SelectMethod="GetCategories"
        InsertMethod="InsertCategory"
        UpdateMethod="UpdateCategory"
        DeleteMethod="DeleteCategory">
        <DeleteParameters>
            <asp:Parameter Name="id" Type="Int32" />
        </DeleteParameters>
        <UpdateParameters>
            <asp:Parameter Name="id" Type="Int32" />
            <asp:Parameter Name="title" Type="String" />
            <asp:Parameter Name="importance" Type="Int32" />
            <asp:Parameter Name="description" Type="String" />
            <asp:Parameter Name="imageUrl" Type="String" />
        </UpdateParameters>
        <InsertParameters>
            <asp:Parameter Name="title" Type="String" />
            <asp:Parameter Name="importance" Type="Int32" />
            <asp:Parameter Name="description" Type="String" />
            <asp:Parameter Name="imageUrl" Type="String" />
        </InsertParameters>
    </asp:ObjectDataSource>
    <asp:GridView ID="gvwCategories" runat="server"
        AutoGenerateColumns="False"
        DataKeyNames="ID"
        DataSourceID="objCategories">
        <Columns>
            <asp:CommandField ShowDeleteButton="True" ShowEditButton="True" />
            <asp:BoundField DataField="Title" HeaderText="Title" SortExpression="Title" />
            <asp:BoundField DataField="Importance" HeaderText="Importance" SortExpression="Importance" />
            <asp:BoundField DataField="Description" HeaderText="Description" SortExpression="Description" />
            <asp:BoundField DataField="ImageUrl" HeaderText="ImageUrl"  SortExpression="ImageUrl" />
            <asp:BoundField DataField="ID" HeaderText="ID" ReadOnly="True" SortExpression="ID" />
            <asp:BoundField DataField="AddedDate" HeaderText="AddedDate" ReadOnly="True" SortExpression="AddedDate" />
            <asp:BoundField DataField="AddedBy" HeaderText="AddedBy" ReadOnly="True" SortExpression="AddedBy" />
        </Columns>
    </asp:GridView>


I made sure to add the DataKeyNames="ID" to the GridView. Yet all I'm getting after selecting the "Edit" from the GridView (ShowEditButton="true") and editing any of the fields is NO CHANGE. And just to recap, this works in the TBH GridView/DetailsView ManageCategories.aspx page.

If anyone can shed some light on what I'm missing I'd be really appreciative.

Thank you,
Ronnie

 
Old December 3rd, 2008, 10:50 PM
Authorized User
 
Join Date: Mar 2008
Posts: 62
Thanks: 1
Thanked 3 Times in 3 Posts
Send a message via Yahoo to kalel_4444
Default

SORRY...!!
Please disregard this post, I've resolved the problem.

I wish I can say how, but I don't know what I did. I just rebuilt the entire page again from scratch and it worked. So I'm assuming a typo somewhere.

Thanks all,
Ronnie

 
Old December 3rd, 2008, 11:08 PM
Lee Dumond's Avatar
Wrox Author
 
Join Date: Jan 2008
Posts: 923
Thanks: 12
Thanked 166 Times in 162 Posts
Default

Delete the following Update parameter:

Code:
<asp:Parameter Name="id" Type="Int32" />
If you are passing in the ID from DataKeyNames, you don't want that in there.

Otherwise, it will always pass in 0 for the ID, the sproc won't find the record, and therefore no update will take place.

If you delete this line, the GridView will pass in the correct ID of the record you are updating, and the update will work.

_________________________________

Visit my blog at http://leedumond.com
 
Old December 4th, 2008, 11:36 PM
Authorized User
 
Join Date: Mar 2008
Posts: 62
Thanks: 1
Thanked 3 Times in 3 Posts
Send a message via Yahoo to kalel_4444
Default

Will do... Thank you Lee






Similar Threads
Thread Thread Starter Forum Replies Last Post
Populating DropDown List in DetailsView Edit Mode. kevorkian ASP.NET 2.0 Professional 2 June 9th, 2008 12:42 PM
problem with populating ddl in edit of detailsview hertendreef ASP.NET 2.0 Professional 1 August 16th, 2007 12:21 PM
Button on GridView that goes to DetailsView AndrewD ASP.NET 2.0 Basics 0 November 30th, 2005 11:09 AM
Can't get DetailsView to work with GridView oneworld95 ASP.NET 2.0 Basics 3 July 16th, 2005 07:19 PM





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