Reputation: 7890
I have this GridView
in my web:
<asp:GridView ID="ClientGridView" runat="server" AutoGenerateColumns="False"
CellPadding="4" DataSourceID="SqlDataSource1" ForeColor="#333333"
GridLines="None" DataKeyNames="id,email,first,last">
<AlternatingRowStyle BackColor="White" />
<Columns>
<asp:TemplateField ShowHeader="False">
<EditItemTemplate>
<asp:LinkButton ID="LinkButton1" runat="server" CausesValidation="True" CommandName="Update" Text="Update"></asp:LinkButton>
<asp:LinkButton ID="LinkButton2" runat="server" CausesValidation="False" CommandName="Cancel" Text="Cancel"></asp:LinkButton>
</EditItemTemplate>
<ItemTemplate>
<asp:LinkButton ID="LinkButton1" runat="server" CausesValidation="False" CommandName="Edit" Text="Edit"></asp:LinkButton>
<asp:LinkButton ID="LinkButton2" runat="server" CausesValidation="False" CommandName="Delete"
onclientclick="javascript:return confirm('are you sure you want to delete.');" Text="Delete"></asp:LinkButton>
</ItemTemplate>
</asp:TemplateField>
<asp:BoundField DataField="id" HeaderText="id" SortExpression="id"/>
<asp:BoundField DataField="email" HeaderText="email" SortExpression="email" />
<asp:BoundField DataField="first" HeaderText="first" SortExpression="first"/>
<asp:BoundField DataField="last" HeaderText="last" SortExpression="last" />
</Columns>
<FooterStyle BackColor="#990000" Font-Bold="True" ForeColor="White" />
<HeaderStyle BackColor="#990000" Font-Bold="True" ForeColor="White" />
<PagerStyle BackColor="#FFCC66" ForeColor="#333333" HorizontalAlign="Center" />
<RowStyle BackColor="#FFFBD6" ForeColor="#333333" />
<SelectedRowStyle BackColor="#FFCC66" Font-Bold="True" ForeColor="Navy" />
<SortedAscendingCellStyle BackColor="#FDF5AC" />
<SortedAscendingHeaderStyle BackColor="#4D0000" />
<SortedDescendingCellStyle BackColor="#FCF6C0" />
<SortedDescendingHeaderStyle BackColor="#820000" />
</asp:GridView>
And this is the SqlDataSource
:
<asp:SqlDataSource ID="SqlDataSource1" runat="server"
ConnectionString="<%$ ConnectionStrings:clientConnectionString %>"
ProviderName="<%$ ConnectionStrings:clientConnectionString.ProviderName %>"
SelectCommand="SELECT * FROM Client;"
DeleteCommand="DELETE FROM Client WHERE id = @id AND email = @email;"
UpdateCommand="UPDATE Client SET first = @first WHERE id = @id;">
<DeleteParameters>
<asp:Parameter Name="id" Type="String" />
<asp:Parameter Name="email" Type="String" />
</DeleteParameters>
<UpdateParameters>
<asp:Parameter Name="id" Type="String" />
<asp:Parameter Name="first" Type="String" />
</UpdateParameters>
</asp:SqlDataSource>
And when i try to excute a update on a row it's stay it the same values and won't Update, any idea how to fix it?
Upvotes: 0
Views: 624
Reputation: 11
If you want update only first row ,Firstly you should use the boundfield read only ture except first hope this should work otherwise use the advice DavidEdwards
Upvotes: 0
Reputation: 593
Based on the UpdateCommand, the First field is the only one updating. Is it updating successfully?
I would think that your Update command would need to be "Update Client Set first = @first, last = @last, email = @email where id = @id"
Upvotes: 1