繁体   English   中英

插入和更新不会与母版页一起推送

[英]Insert and update won't push with a Master page

我们目前正在将ASP经典页面更新为ASP.net,并且在我们的工具集中受到限制(仅VS 2013中的Asp.net可用的工具)。 我们的Web应用程序是MSSQL数据库(SQL Server 2008)的前端。 我们遇到了来自FormView的插入和更新命令的问题。 当我们不使用母版页时,一切都将完美运行,但是当我们应用母版页和内容占位符时,数据将无法推送。 我们可以删除记录,但不能获取要更改/插入表中的数据。 当insert命令运行时,它将创建一个没有数据的新记录。 我们尝试使用ClientID设置的所有变体,并查看状态模式(这是我们认为问题所在的位置)。 任何帮助,将不胜感激。

页面标题

<%@ Page Title="TEST" Language="C#" MasterPageFile="~/MASTERSTYLE/MXGWeb.master" AutoEventWireup="True" CodeFile="Default2.aspx.cs" Inherits="ETO_Trax_Default2" %>
<asp:Content ID="Content1" ContentPlaceHolderID="Head" Runat="Server"></asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="MainContent" Runat="Server" ClientIDMode="Static">

表格检视

<asp:FormView ID="ETOFormView" runat="server" DataSourceID="ETOFormSQLDataSource" OnItemUpdated="ETOFormView_ItemUpdated" OnItemDeleted="ETOFormView_ItemDeleted"  DataKeyNames="ID">
<EditItemTemplate>
ID:<asp:Label Text='<%# Eval("ID") %>' runat="server" ID="IDLabel1" /><br />
ETOType: <asp:TextBox Text='<%# Bind("ETOType") %>' runat="server" ID="ETOTypeTextBox"/><br />
<asp:LinkButton runat="server" Text="Update" CommandName="Update" ID="UpdateButton" CausesValidation="True" />&nbsp;<asp:LinkButton runat="server" Text="Cancel" CommandName="Cancel" ID="UpdateCancelButton" CausesValidation="False" />
</EditItemTemplate>
<InsertItemTemplate>
ETOType:<asp:TextBox Text='<%# Bind("ETOType") %>' runat="server" ID="ETOTypeTextBox" /><br />    
<asp:LinkButton runat="server" Text="Insert" CommandName="Insert" ID="InsertButton" CausesValidation="True" />&nbsp;<asp:LinkButton runat="server" Text="Cancel" CommandName="Cancel" ID="InsertCancelButton" CausesValidation="False" />
</InsertItemTemplate>
<ItemTemplate>
ID:<asp:Label Text='<%# Eval("ID") %>' runat="server" ID="IDLabel" /><br />
ETOType:<asp:Label Text='<%# Bind("ETOType") %>' runat="server" ID="ETOTypeLabel" /><br />
<asp:LinkButton runat="server" Text="Edit" CommandName="Edit" ID="EditButton" CausesValidation="False" />&nbsp;<asp:LinkButton runat="server" Text="Delete" CommandName="Delete" ID="DeleteButton" CausesValidation="False" />&nbsp;<asp:LinkButton runat="server" Text="New" CommandName="New" ID="NewButton" CausesValidation="False" />
</ItemTemplate>
</asp:FormView>

SQL数据源:

<asp:SqlDataSource ID="ETOFormSQLDataSource" runat="server" ConnectionString='<%$ ConnectionStrings:SQLConnectionString %>’
    DeleteCommand="DELETE FROM [TABLE] WHERE [ID] = @ID"
    InsertCommand="INSERT INTO [TABLE] ([VALUE]) VALUES (@VALUE) SELECT @ID = SCOPE_IDENTITY()"
    SelectCommand="SELECT * FROM [TABLE] WHERE [ID] = @ID"
    UpdateCommand="UPDATE TABLE SET VALUE=@VALUE WHERE ID=@ID" 
    OnInserted="ETOFormSQLDataSource_Inserted">
<SelectParameters>
        <asp:Parameter Name="ID" Type="Int32" DefaultValue="0" />
    </SelectParameters>
    <DeleteParameters>
        <asp:Parameter Name="ID" Type="Int32"></asp:Parameter>
    </DeleteParameters>
    <InsertParameters>
        <asp:Parameter Name="ID" Direction="Output" Type="int32"></asp:Parameter>
    </InsertParameters>
</asp:SqlDataSource>

InsertParameters集合只有一个参数是输出参数,因此无法插入任何值,因为它不知道如何传递该信息:

<InsertParameters>
 <asp:Parameter Name="ID" Direction="Output" Type="int32"></asp:Parameter>
 <asp:Parameter Name="ETOType" Type="WhateverItIs"></asp:Parameter>
</InsertParameters>

请注意,新参数名为ETOType,因为这是视图中用于绑定控件的名称。

我什至没有添加必需的参数,因为INSERT sql命令应该变成:

INSERT INTO [TABLE] ([VALUE]) VALUES (@ETOType) SELECT @ID = SCOPE_IDENTITY()

这是因为在视图代码中ETOTypeBind内使用的名称,也是分配给该参数的名称,这是装订器期望的值。

不确定,但可能是INSERT查询的正确语法应与语句终止符一起使用:

INSERT INTO [TABLE] ([VALUE]) VALUES (@ETOType); SELECT @ID = SCOPE_IDENTITY();

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM