[英]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" /> <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" /> <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" /> <asp:LinkButton runat="server" Text="Delete" CommandName="Delete" ID="DeleteButton" CausesValidation="False" /> <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()
這是因為在視圖代碼中ETOType
是Bind
內使用的名稱,也是分配給該參數的名稱,這是裝訂器期望的值。
不確定,但可能是INSERT
查詢的正確語法應與語句終止符一起使用:
INSERT INTO [TABLE] ([VALUE]) VALUES (@ETOType); SELECT @ID = SCOPE_IDENTITY();
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.