我有一个从 3 个表中正确填充的 gridview。当我更新它时,它只会更新一个字段(Kommentar),但只会更新第一次。
<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" DataKeyNames="ID,Erledigt,Kommentar"
DataSourceID="ArtikelDataSource">
<Columns>
<asp:CommandField ShowEditButton="True" />
<asp:BoundField DataField="Name" HeaderText="Name" SortExpression="Name"
ReadOnly="True" >
<ControlStyle Width="150px" />
</asp:BoundField>
<asp:BoundField DataField="Beschreibung" HeaderText="Beschreibung"
SortExpression="Beschreibung" ReadOnly="True" >
<ControlStyle Width="200px" />
</asp:BoundField>
<asp:BoundField DataField="Datum" HeaderText="Datum" SortExpression="Datum"
ReadOnly="True" >
<ControlStyle Width="100px" />
</asp:BoundField>
<asp:BoundField DataField="Erledigt" HeaderText="Erledigt"
SortExpression="Erledigt" >
<ControlStyle Width="50px" />
</asp:BoundField>
<asp:BoundField DataField="Kommentar" HeaderText="Kommentar"
SortExpression="Kommentar" >
<ControlStyle Width="200px" />
</asp:BoundField>
<asp:BoundField DataField="LastUpdate" HeaderText="LastUpdate"
SortExpression="LastUpdate" ReadOnly="True" />
<asp:BoundField DataField="ID" HeaderText="ID" InsertVisible="False"
ReadOnly="True" SortExpression="ID" Visible="False" />
</Columns>
</asp:GridView>
<asp:SqlDataSource ID="ArtikelDataSource" runat="server"
ConnectionString="<%$ ConnectionStrings:MyConnectionString %>"
SelectCommand="SELECT ci.Name, ci.Beschreibung, ca.ChkItemID, ca.ChkUserID, ca.Datum, ca.Erledigt, ca.Kommentar, ca.LastUpdate, ca.ID FROM ChecklistActions AS ca INNER JOIN ChecklistItems AS ci ON ca.ChkItemID = ci.ID INNER JOIN ChecklistUsers AS cu ON ca.ChkUserID = cu.ID WHERE (ca.Datum = @datum) AND (cu.Login = @userlogin)"
UpdateCommand="UPDATE ChecklistActions SET Kommentar = @Kommentar, LastUpdate = GETDATE() WHERE (ID = @ID)"
OnSelecting="_data_Selecting"
>
<SelectParameters>
<asp:Parameter Name="userlogin"/>
<asp:Parameter Name="datum"/>
</SelectParameters>
<UpdateParameters>
<asp:Parameter Name="Kommentar" Type="string"/>
<asp:Parameter Name="ID" />
</UpdateParameters>
</asp:SqlDataSource>
我首先有一个空字段“Kommentar”,然后它被填充,但是当我再次尝试更改值时,只有 GETDATE() 更改值,Kommentar 的内容与以前相同。
当我尝试通过 SQL 更改“Erledigt”的值时
UpdateCommand="UPDATE ChecklistActions SET Erledigt = @Erledigt, Kommentar = @Kommentar, LastUpdate = GETDATE() WHERE (ID = @ID)"
...
<asp:Parameter Name="Erledigt" Type="Int32"/>
什么都没有更新(除了 Getdate()) - 甚至没有第一次更新字段 Kommentar
似乎 gridview 正在将旧值发送到更新命令(只有第一个更新会收到新的 Kommentar 值),这真的很烦人吗?