I have a very simple setup that should work fine per documentation. However,
my gridview control will not properly update using the updatecommand of the
sqldatasource. I've simplified everything below. I'd like to be able to see a
table of results in my gridview, click edit on any particular record, modify
the data, then click update. What I find is happening is that my parameters
are not being updated when I go into edit mode, change the text of the
"firstName" field, and click update. In the OnUpdating method of the
sqldatasource, I've stepped through the command parameters collection and it
always contains the original values, not what I've typed into the editable
textboxes in my grid.
<asp:GridView ID="gvContacts" PageSize="200" DataKeyNames="id"
CssClass="GridViewStyle" GridLines="both" AllowSorting="true" runat="server"
AutoGenerateColumns="False" DataSourceID="SqlDataSource1"
AllowPaging="True" Width="98%" Visible="true" >
<Columns>
<asp:BoundField DataField="firstName" HeaderText="First Name"
SortExpression="firstName" HeaderStyle-HorizontalAlign="center"
HeaderStyle-VerticalAlign="middle" >
</asp:BoundField>
<asp:CommandField ShowEditButton="true" ShowDeleteButton="true" />
</Columns>
</asp:GridView>
<asp:SqlDataSource
ID="SqlDataSource1"
runat="server"
OldValuesParameterFormatString="original_{0}"
ProviderName="System.Data.SqlClient"
ConnectionString="<%$ ConnectionStrings:MyConnectionString%>"
SelectCommand="SELECT id, firstName, lastName, email, phone, importance,
message, subscribeToNewsletter, howDidYouHearAboutUs, createdBy, dateCreated,
lastUpdateBy, lastUpdateDate FROM Contacts"SelectCommandType="text"
UpdateCommand = "UPDATE Contacts SET firstName=@firstName where
id=@original_id"
UpdateCommandType="text"
DeleteCommand="DELETE FROM Contacts WHERE id=@original_id"
DeleteCommandType="Text">
</asp:SqlDataSource>
--
PK9