未从 DetailsView (ASPX/C#) 正确填充 SQL 语句
我在 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 Profiler 将其执行的命令显示为 UPDATE ATI_CHANGE_REQUESTS SET Completed=0 WHERE ChangeID=53
,但无论是否选中 DetailsView4 中的复选框,它总是已完成集=0。我做错了什么?
I've got the following code in an ASPX page:
<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>
And it appears, for the most part, to work correctly. It pulls the correct ChangeID from the gridview I referenced in the ControlParameter, but it never actually updates anything. SQL Profiler shows the command it executes as UPDATE ATI_CHANGE_REQUESTS SET Completed=0 WHERE ChangeID=53
when I've got the row with ChangeID 53 seleced, but whether the checkbox in DetailsView4 is checked or not, it always sets Completed=0. What have I done wrong?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
事实证明,我的 SQL 数据源由于某种未知原因而被破坏,重新创建 SqlDataSource1 完全解决了问题,但我仍然不知道为什么。无论如何,谢谢:)
It turns out my SQL Data Source was hosed for some unknown reason, recreating SqlDataSource1 completely fixed the problem and I still have no idea why. Thanks anyway :)