Monday, May 21, 2012

Gridview not updating all fields

I have a gridview that is filled correctly from 3 tables.
When I update it, it will only update one field (Kommentar) but only the first time.

    <asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" DataKeyNames="ID,Erledigt,Kommentar"
<asp:CommandField ShowEditButton="True" />
<asp:BoundField DataField="Name" HeaderText="Name" SortExpression="Name"
ReadOnly="True" >
<ControlStyle Width="150px" />
<asp:BoundField DataField="Beschreibung" HeaderText="Beschreibung"
SortExpression="Beschreibung" ReadOnly="True" >
<ControlStyle Width="200px" />
<asp:BoundField DataField="Datum" HeaderText="Datum" SortExpression="Datum"
ReadOnly="True" >
<ControlStyle Width="100px" />
<asp:BoundField DataField="Erledigt" HeaderText="Erledigt"
SortExpression="Erledigt" >
<ControlStyle Width="50px" />
<asp:BoundField DataField="Kommentar" HeaderText="Kommentar"
SortExpression="Kommentar" >
<ControlStyle Width="200px" />
<asp:BoundField DataField="LastUpdate" HeaderText="LastUpdate"
SortExpression="LastUpdate" ReadOnly="True" />
<asp:BoundField DataField="ID" HeaderText="ID" InsertVisible="False"
ReadOnly="True" SortExpression="ID" Visible="False" />
<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)"
<asp:Parameter Name="userlogin"/>
<asp:Parameter Name="datum"/>
<asp:Parameter Name="Kommentar" Type="string"/>
<asp:Parameter Name="ID" />

I have first an empty field "Kommentar", then it is filled, but when I try to change the value again, only the GETDATE() changes value, the content of Kommentar is the same as before.

When I try to change the value of "Erledigt" via SQL

UpdateCommand="UPDATE ChecklistActions SET Erledigt = @Erledigt Kommentar = @Kommentar, LastUpdate = GETDATE() WHERE (ID = @ID)" 
<asp:Parameter Name="Erledigt" Type="Int32"/>

nothing (except the Getdate()) is updated at all - not even the field Kommentar at the fist time

It seems that the gridview is sending the old values to the update command (only the first update will receive the new Kommentar-value) which is really irritating ?

No comments:

Post a Comment