Wrox Programmer Forums
Go Back   Wrox Programmer Forums > ASP.NET and ASP > ASP.NET 2.0 > ASP.NET 2.0 Basics
ASP.NET 2.0 Basics If you are new to ASP or ASP.NET programming with version 2.0, this is the forum to begin asking questions. Please also see the Visual Web Developer 2005 forum.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the ASP.NET 2.0 Basics 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 January 5th, 2007, 11:35 PM
Registered User
Join Date: Jan 2007
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default GridView -- How do I do custom updates?

I have a gridview that specifies a method to run in a codebehind page via the OnRowUpdating attribute. When I execute this update, I can clearly see that my stored procedure is being called twice (I verified this using SQL Profiler). The first time it’s called, it is being executed via the code in my code-behind page. The second time it’s called, it’s being called “automatically” thru the asp.net built-in gridview functionality in asp.net, and I’m receiving the following error: Procedure or function usp_RenameFolder has too many arguments specified. The really annoying thing is that the first time my sproc is called (via the codebehind code), it’s working just fine, but I can’t find a way to “turn off” the second time it gets called (the “built in” way). I wish to somehow stop the sproc from being called a second time.

Here’s the pertinent parts of gridview. If you want to see the whole thing, please don’t hesitate to ask.

    <asp:GridView ID="gvRootFolders" runat="server" blah blah blah OnRowUpdating="gvRootFolders_RowUpdating">

        â€¦Blah blah blah…

                    <asp:TextBox ID="FolderNameField" Text='<%# Bind("FolderName") %>'
                        runat="server" MaxLength="256" ValidationGroup="EditDelete">

        â€¦blah blah blah…


Here’s the data source code:

    <asp:SqlDataSource ID="MyDataSource" runat="server" ConnectionString="<%$ ConnectionStrings:MyConnectionString %>"
        DeleteCommand="usp_DeleteRootFolder" DeleteCommandType="StoredProcedure" InsertCommand="usp_AddRootFolder"
        InsertCommandType="StoredProcedure" SelectCommand="usp_GetRootFolders"
        SelectCommandType="StoredProcedure" UpdateCommand="usp_RenameFolder"
            <asp:Parameter Name="FolderID" Type="Int32" />
            <asp:Parameter Name="OldFolderName" Type="string" />
            <asp:Parameter Name="NewFolderName" Type="string" />
            <asp:Parameter Name="ModifiedBy" Type="Int32" />

My “code behind” code works. It is a method called gvRootFolders_RowUpdating that creates a SQLConnection and executes the usp_RenameFolder stored procedure in exactly the way I want to execute it (i.e. there’s error handling using recordsets and return values).

My question is: How can I disable the “built-in” updating functionality, while still allowing my custom code-behind update code to run?

Things I have already tried:
1) Remove the UpdateCommand and UpdateCommandType attributes from the asp:SqlDataSource tag
a. Result: I receive the following error message when executing an update: Updating is not supported by data source 'DocCentral' unless UpdateCommand is specified.
2) Remove the <UpdateParameters> tag (and all of its child tags) altogether
a. Result: I receive the following error message when executing an update: Procedure or Function 'usp_RenameFolder' expects parameter '@OldFolderName', which was not supplied.


Old November 16th, 2007, 03:26 PM
Registered User
Join Date: Jan 2007
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts

By the way, a belated thank you for this. It works perfectly!
Old January 3rd, 2008, 06:00 PM
Registered User
Join Date: Jan 2008
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts

I noticed that this also happens when the CausesValidation attribute is set to false for the asp:CommandField in the gridview.

I removed it from the attributes in the aspx page and OnRowEditing stopped processing twice.

Similar Threads
Thread Thread Starter Forum Replies Last Post
Performance Penalty for Custom Code Gridview Row B wirerider ASP.NET 2.0 Professional 0 April 5th, 2006 04:43 PM
Custom Postback and Gridview refresh wirerider ASP.NET 2.0 Basics 5 February 28th, 2006 04:33 PM
Gridview custom buttons wirerider ASP.NET 2.0 Basics 2 February 5th, 2006 02:49 PM
Custom GridView bmains ASP.NET 2.0 Basics 0 August 8th, 2005 03:06 PM
Custom GridView (maybe?) bmains ASP.NET 2.0 Basics 0 April 18th, 2005 09:48 AM

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