ASP.NET ObjectDataSource, change CommandName property of FromView Button

Posted by Tone on Stack Overflow See other posts from Stack Overflow or by Tone
Published on 2009-09-27T01:09:08Z Indexed on 2010/03/17 17:51 UTC
Read the original article Hit count: 281

Filed under:
|
|

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>

© Stack Overflow or respective owner

Related posts about ASP.NET

Related posts about formview