ASP.NET ObjectDataSource,更改 FormView 按钮的 CommandName 属性

发布于 2024-08-05 10:03:01 字数 2861 浏览 5 评论 0原文

我有一个与 FormView 一起使用的 ObjectDataSource,它工作正常,但我想更改一件小事情。在 FormView 上,触发更新的按钮将 CommandName 属性设置为“更新”,但我想将该属性更改为“更新”以外的其他属性 - 当我更改该属性时,更新将不再起作用。我想这样做的原因是我在同一页面上有多个 FormView,并且需要有多个更新按钮。下面是我的代码:

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>  

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>  

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

护你周全 2024-08-12 10:03:01

每个 FormView 都有自己的事件来处理更新,因此不同 FormView 的 CommandName 相同应该不是问题。

如果出现问题,您可以通过更改按钮的文本值来更改按钮的名称。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文