Help | Site Map
Connecting Tech Pros Worldwide
 
 
LinkBack Thread Tools
  #1  
Old October 12th, 2008, 01:05 AM
=?Utf-8?B?UEs5?=
Guest
 
Posts: n/a
Default GridView not Updating Through SqlDataSource

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
 

Bookmarks

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are Off
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

What is Bytes?

We are a network of experts and professionals in IT and software development that help one another with answers to tough questions and share insights. Get the best answers to your questions from over network members.
Post your question now . . .
It's fast and it's free

Popular Articles