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"
<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.