Windows Vista Forums
Vista Forums Home Join Vista Forums Windows 7 Forum Vista Tutorials Tags
Welcome to Windows Vista Forums. Our forum is dedicated to helping you find solutions with any problems, errors or issues you are experiencing with Windows Vista. The Vista forum also covers news and updates and has an extensive Windows Vista tutorial section that covers a wide range of tips and tricks.

Go Back   Vista Forums > Misc Newsgroups > .NET General

Vista Tutorial - GridView not Updating Through SqlDataSource

Reply
 
Old 10-11-2008   #1 (permalink)
PK9
Guest


 
 

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

My System SpecsSystem Spec
Reply

Thread Tools


Similar Threads
Thread Forum
Sqldatasource Update .NET General
VB.NET: dynamically change SqlDataSource SelectCommand and re-exec .NET General
How to reset the SelectCommand of a SqlDataSource on the client(JavaScript)? .NET General
newbie question on SqlDataSource object .NET General
CTP Out-GridView PowerShell


Vista Forums is an independent web site and has not been authorized,
sponsored, or otherwise approved by Microsoft Corporation.
"Windows Vista", the Start Orb, and related materials are trademarks of Microsoft Corp.
© Designer Media Ltd

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46