从DetailsView(ASPX / C#)未正确填充SQL语句

时间:2011-06-17 19:39:07

标签: c# asp.net sql gridview dataview

我在ASPX页面中有以下代码:

        <asp:DetailsView ID="DetailsView4" runat="server" AutoGenerateRows="False" 
            DataKeyNames="ChangeID,Completed" DataSourceID="SqlDataSource5" Height="50px" 
            Width="125px">
            <Fields>
                <asp:CheckBoxField DataField="Completed" HeaderText="Completed" 
                    SortExpression="Completed" />
                <asp:CommandField ShowEditButton="True" />
            </Fields>
        </asp:DetailsView>


<asp:SqlDataSource ID="SqlDataSource5" runat="server" 
    ConnectionString="<%$ ConnectionStrings:Properties %>" 

    SelectCommand="SELECT * FROM [ATI_CHANGE_REQUESTS] WHERE ([ChangeID] = @ChangeID)" 
    UpdateCommand="UPDATE ATI_CHANGE_REQUESTS SET Completed = @Completed WHERE ChangeID = @ChangeID">
    <SelectParameters>
        <asp:ControlParameter ControlID="grdRequests" Name="ChangeID" 
            PropertyName="SelectedDataKey[1]" Type="Int32" />
    </SelectParameters>
    <UpdateParameters>
        <asp:Parameter Name="Completed" />
        <asp:Parameter Name="ChangeID" />
    </UpdateParameters>
</asp:SqlDataSource>

在大多数情况下,它似乎正常工作。它从我在ControlParameter中引用的gridview中提取正确的ChangeID,但它实际上从未更新任何内容。当我获得带有ChangeID 53的行时,SQL事件探查器会显示它作为UPDATE ATI_CHANGE_REQUESTS SET Completed=0 WHERE ChangeID=53执行的命令,但无论DetailsView4中的复选框是否被选中,它总是设置为Completed = 0。我做错了什么?

1 个答案:

答案 0 :(得分:0)

事实证明我的SQL数据源因某些未知原因而被清除,重新创建SqlDataSource1完全修复了问题,我仍然不知道为什么。无论如何,谢谢:)