更新命令不适用于特定页面

时间:2013-04-13 16:48:55

标签: c# asp.net sql sql-server-2008 sql-update

我在我拥有的页面上遇到了更新命令的问题。我有4个网格视图和4个详细信息视图,它们都不会使用update命令更新。我可以插入和删除但更新不起作用。更新按钮不会导致回发,它只是坐在那里。

我创建了一个新页面并添加了一个detailsview并将其连接到同一个数据库和同一个表,并且在该页面中,update命令工作正常。我甚至将命令查询复制并粘贴到另一页的详细信息视图中,但没有成功。

我认为这是按钮的问题,但为什么默认的更新链接按钮不起作用?

我正在使用ASP.NET,C#和SQL Server 2008。

我注意到详细信息视图中的更新按钮显示了状态栏上的javascript:__doPostBack('DetailsView1$ctl02','')

但无效的更新按钮会显示:WebForm_PostBackOptions("ctl00$ContentPlaceHolder1$DetailsView2$ctl02", "", true, "", "", false, true))

以下是详情视图的代码

<asp:DetailsView ID="DetailsView1" runat="server" AutoGenerateRows="False" 
DataKeyNames="WorkshopName,WorkshopBeginingDate,WorkshopLocation" 
DataSourceID="SqlDataSource1" Height="50px" Width="125px">
<Fields>
<asp:BoundField DataField="WorkshopName" HeaderText="WorkshopName" 
ReadOnly="True" SortExpression="WorkshopName" />
<asp:BoundField DataField="WorkshopBeginingDate" 
HeaderText="WorkshopBeginingDate" ReadOnly="True" 
SortExpression="WorkshopBeginingDate" />
<asp:BoundField DataField="WorkshopEndingDate" HeaderText="WorkshopEndingDate" 
SortExpression="WorkshopEndingDate" />
<asp:BoundField DataField="WorkshopLocation" HeaderText="WorkshopLocation" 
ReadOnly="True" SortExpression="WorkshopLocation" />
    <asp:CommandField ShowEditButton="True" />
    </Fields>
</asp:DetailsView>

这是不起作用的代码

   <asp:DetailsView ID="DetailsView2" runat="server" AutoGenerateRows="False" 
                                    DataKeyNames="WorkshopName,WorkshopBeginingDate,WorkshopLocation" 
    DataSourceID="SqlDataSource20" Height="50px" Width="125px">
    <Fields>
    <asp:BoundField DataField="WorkshopName" HeaderText="WorkshopName" 
    ReadOnly="True" SortExpression="WorkshopName" />
    <asp:BoundField DataField="WorkshopBeginingDate" 
    HeaderText="WorkshopBeginingDate" ReadOnly="True" 
    SortExpression="WorkshopBeginingDate" />
    <asp:BoundField DataField="WorkshopEndingDate" HeaderText="WorkshopEndingDate" 
    SortExpression="WorkshopEndingDate" />
    <asp:BoundField DataField="WorkshopLocation" HeaderText="WorkshopLocation" 
    ReadOnly="True" SortExpression="WorkshopLocation" />
    <asp:CommandField ShowEditButton="True" />
    </Fields>
    </asp:DetailsView>

**This is the SQL Data source code for the one that doesn't work, it is also the same on the one that works, except for the Datasource ID.**

<asp:SqlDataSource ID="SqlDataSource1" runat="server" 
        ConflictDetection="CompareAllValues" 
        ConnectionString="<%$ ConnectionStrings:WildLife_EducationConnectionString %>" 
        DeleteCommand="DELETE FROM [tblWorkshop] WHERE [WorkshopName] = @original_WorkshopName AND [WorkshopBeginingDate] = @original_WorkshopBeginingDate AND [WorkshopLocation] = @original_WorkshopLocation AND (([WorkshopEndingDate] = @original_WorkshopEndingDate) OR ([WorkshopEndingDate] IS NULL AND @original_WorkshopEndingDate IS NULL))" 
        InsertCommand="INSERT INTO [tblWorkshop] ([WorkshopName], [WorkshopBeginingDate], [WorkshopEndingDate], [WorkshopLocation]) VALUES (@WorkshopName, @WorkshopBeginingDate, @WorkshopEndingDate, @WorkshopLocation)" 
        OldValuesParameterFormatString="original_{0}" 
        SelectCommand="SELECT [WorkshopName], [WorkshopBeginingDate], [WorkshopEndingDate], [WorkshopLocation] FROM [tblWorkshop]" 
        UpdateCommand="UPDATE [tblWorkshop] SET [WorkshopEndingDate] = @WorkshopEndingDate WHERE [WorkshopName] = @original_WorkshopName AND [WorkshopBeginingDate] = @original_WorkshopBeginingDate AND [WorkshopLocation] = @original_WorkshopLocation AND (([WorkshopEndingDate] = @original_WorkshopEndingDate) OR ([WorkshopEndingDate] IS NULL AND @original_WorkshopEndingDate IS NULL))">
        <DeleteParameters>
            <asp:Parameter Name="original_WorkshopName" Type="String" />
            <asp:Parameter DbType="Date" Name="original_WorkshopBeginingDate" />
            <asp:Parameter Name="original_WorkshopLocation" Type="String" />
            <asp:Parameter DbType="Date" Name="original_WorkshopEndingDate" />
        </DeleteParameters>
        <InsertParameters>
            <asp:Parameter Name="WorkshopName" Type="String" />
            <asp:Parameter DbType="Date" Name="WorkshopBeginingDate" />
            <asp:Parameter DbType="Date" Name="WorkshopEndingDate" />
            <asp:Parameter Name="WorkshopLocation" Type="String" />
        </InsertParameters>
        <UpdateParameters>
            <asp:Parameter DbType="Date" Name="WorkshopEndingDate" />
            <asp:Parameter Name="original_WorkshopName" Type="String" />
            <asp:Parameter DbType="Date" Name="original_WorkshopBeginingDate" />
            <asp:Parameter Name="original_WorkshopLocation" Type="String" />
            <asp:Parameter DbType="Date" Name="original_WorkshopEndingDate" />
        </UpdateParameters>
    </asp:SqlDataSource>

1 个答案:

答案 0 :(得分:0)

经过数周的研究,我决定从我的页面中删除所有的ajax,并且更新开始工作得很漂亮。显然,一些代码与页面上的更新命令冲突。

我已经研究了这个问题好几周了,多次读取数据源但没有成功。我的最后一个资源是从页面中删除所有的ajax并且奇迹般地一切正常。