We are currently updating our asp classic pages to ASP.net and are limited in our toolset (only tools available with Asp.net in VS 2013). Our web apps are a front end for MSSQL databases (SQL Server 2008). We are running into an issue with Insert and Update commands from a FormView. When we do not use a master page everything works perfectly, but when we apply a master page and content placeholders, the data does not push. We can delete records fine, but we cannot get data to change/insert into the tables. When the insert command runs it creates a new record with no data. We've tried using all variations of the ClientID setting, and view state modes (which is where we think the problem is). Any help would be appreciated.
Page Header
<%@ 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">
Form View
<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 Data Source:
<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>
答案 0 :(得分:0)
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();