asp.netobjectdatasourceformview

ASP.NET ObjectDataSource, change CommandName property of FormView Button


I have an ObjectDataSource that I'm using with a FormView, and it works fine, but i want to change one small thing. On the FormView the button that fires the update has the CommandName attribute set to "Update," but I would like to change that attribute to something other than "Update" - when I do change that attribute the update no longer works. The reason I want to do this is I have multiple FormViews on the same page and need to have multiple update buttons. Below is my code:

FormView:

            <asp:FormView ID="fvGeneralInfo" runat="server" 
            DataSourceID="objInstructorDetails" CssClass="Gridview"
            OnItemCommand="fvGeneralInfo_ItemCommand"
            DefaultMode="Edit">
            <EditItemTemplate>
            <table>  
               ....
                    <tr>
                        <td style="text-align:right;">
                            <asp:Label runat="server" ID="lblGeneralInfoMessage" Text="General Info updated successfully" Visible="false" />
                        </td>
                        <td>
                            <asp:Button runat="server" ID="btnUpdateGeneralInfo" ValidationGroup="UpdateGeneralInfo" Text="Update" CommandName="Update" />
                            <asp:Button runat="server" ID="btnCancelGeneralInfo" Text="Cancel" CommandName="CancelGeneralInfo" />
                        </td>
                    </tr>
                </table>  
            </EditItemTemplate>
        </asp:FormView>

ObjectDataSource:

    <asp:ObjectDataSource ID="objInstructorDetails" runat="server" TypeName="AIMLibrary.BLL.Instructor" SelectMethod="GetInstructorDetails" 
 InsertMethod="InsertInstructor" UpdateMethod="UpdateInstructor" OnInserting="objInstructorDetails_OnInserting" 
 OnUpdating="objInstructorDetails_OnUpdating" >         
    <SelectParameters>
        <asp:QueryStringParameter Name="InstructorId" QueryStringField="InstructorId" />
    </SelectParameters>
    <UpdateParameters>
        <asp:Parameter Name="instructorId" Type="Int32" />
        <asp:Parameter Name="firstName" Type="String" DefaultValue="" />
        <asp:Parameter Name="middleName" Type="String" DefaultValue="" />
        <asp:Parameter Name="lastName" Type="String" DefaultValue="" />
        <asp:Parameter Name="phone" Type="String" DefaultValue="" />
        <asp:Parameter Name="email" Type="String" DefaultValue="" />
        <asp:Parameter Name="addressLine1" Type="String" DefaultValue="" />
        <asp:Parameter Name="addressLine2" Type="String" DefaultValue="" />
        <asp:Parameter Name="city" Type="String" DefaultValue="" />
        <asp:Parameter Name="state" Type="String" DefaultValue="" />
        <asp:Parameter Name="zip" Type="String" DefaultValue="" />
        <asp:Parameter Name="abcBoardNumber" Type="String" DefaultValue="" />
    </UpdateParameters>
</asp:ObjectDataSource>  

Solution

  • Each FormView will have it's own event for handling updates so the CommandName being the same for different FormViews should not be a problem.

    You can change the name of the buttons if that's an issue by changing it's text value.