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â¦
<EditItemTemplate>
<asp:TextBox ID="FolderNameField" Text='<%# Bind("FolderName") %>'
runat="server" MaxLength="256" ValidationGroup="EditDelete">
</asp:TextBox>
</EditItemTemplate>
â¦blah blah blahâ¦
</asp:GridView>
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"
UpdateCommandType="StoredProcedure">
<UpdateParameters>
<asp:Parameter Name="FolderID" Type="Int32" />
<asp:Parameter Name="OldFolderName" Type="string" />
<asp:Parameter Name="NewFolderName" Type="string" />
<asp:Parameter Name="ModifiedBy" Type="Int32" />
</UpdateParameters>
</asp:SqlDataSource>
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.
Help!
-Matt
|