Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
?
Solved

GridView won't update - Single table, all fields,

Posted on 2009-02-08
3
Medium Priority
?
401 Views
Last Modified: 2013-11-07
I keep having a problem with GridView records not Updating when I select Edit and Update.
I've included all columns from the table, enabled Paging, Sorting, Editing, Deleting and Selection
In Configure DateSource:
All columns selected, "*".  I've also used, and more often, Specify a custome SQL statement with all the columns included.
Return only unique rows - Not checked
Generate INSERT, UPDATE, and DELETE statements - Checked
Use optimistic concurrency - Not Checked

In the GridView when I select Edit, then change date and click Update, the data is not changed, it keeps the original value.  I've verified this in the database.

I've found it to be just hit-or-miss.  Sometimes it works and sometimes it doesn't and sometimes it will work for a while then stop working.  It's starting to really frustrate me BAD.  I use GirdViews all the time, but it seems they are "touchy", I'm afraid to mess with one that works or it will stop working.

Below are my GridView and SqlDataSource exactly as is.  I have nothing else on the page.  Everything is freshly created.  
If someone can tell me what I'm doing wrong I'd really appreciate it.

Updates do not work with this:

<asp:GridView ID="GridView1" runat="server" AllowPaging="True" AllowSorting="True"
                  AutoGenerateColumns="False" BackColor="White" BorderColor="#E7E7FF" BorderStyle="None"
                  BorderWidth="1px" CellPadding="3" DataKeyNames="SuggestionID" DataSourceID="SqlDataSource1"
                  GridLines="Horizontal">
                  <RowStyle BackColor="#E7E7FF" ForeColor="#4A3C8C" />
                  <Columns>
                        <asp:CommandField ShowDeleteButton="True" ShowEditButton="True" ShowSelectButton="True" />
                        <asp:BoundField DataField="SuggestionID" HeaderText="SuggestionID" InsertVisible="False" ReadOnly="True" SortExpression="SuggestionID" />
                        <asp:BoundField DataField="LastName" HeaderText="LastName" SortExpression="LastName" />
                        <asp:BoundField DataField="FirstName" HeaderText="FirstName" SortExpression="FirstName" />
                        <asp:BoundField DataField="EmailAddress" HeaderText="EmailAddress" SortExpression="EmailAddress" />
                        <asp:BoundField DataField="SuggestionDate" HeaderText="SuggestionDate" SortExpression="SuggestionDate" />
                        <asp:BoundField DataField="Location" HeaderText="Location" SortExpression="Location" />
                        <asp:BoundField DataField="Summary" HeaderText="Summary" SortExpression="Summary" />
                        <asp:BoundField DataField="Suggestion" HeaderText="Suggestion" SortExpression="Suggestion" />
                        <asp:BoundField DataField="Goal" HeaderText="Goal" SortExpression="Goal" />
                        <asp:BoundField DataField="HowToAchieve" HeaderText="HowToAchieve" SortExpression="HowToAchieve" />
                        <asp:BoundField DataField="CostSavings" HeaderText="CostSavings" SortExpression="CostSavings" />
                        <asp:BoundField DataField="SupportingDocs" HeaderText="SupportingDocs" SortExpression="SupportingDocs" />
                        <asp:BoundField DataField="Attachment" HeaderText="Attachment" SortExpression="Attachment" />
                        <asp:BoundField DataField="SubmittedDate" HeaderText="SubmittedDate" SortExpression="SubmittedDate" />
                        <asp:CheckBoxField DataField="Approved" HeaderText="Approved" SortExpression="Approved" />
                        <asp:BoundField DataField="DecisionDate" HeaderText="DecisionDate" SortExpression="DecisionDate" />
                        <asp:BoundField DataField="Comments" HeaderText="Comments" SortExpression="Comments" />
                        <asp:CheckBoxField DataField="AwardGiven" HeaderText="AwardGiven" SortExpression="AwardGiven" />
                        <asp:BoundField DataField="AwardAmount" HeaderText="AwardAmount" SortExpression="AwardAmount" />
                        <asp:BoundField DataField="EstCostSavings" HeaderText="EstCostSavings" SortExpression="EstCostSavings" />
                        <asp:BoundField DataField="ReviewedBy" HeaderText="ReviewedBy" SortExpression="ReviewedBy" />
                  </Columns>
                  <FooterStyle BackColor="#B5C7DE" ForeColor="#4A3C8C" />
                  <PagerStyle BackColor="#E7E7FF" ForeColor="#4A3C8C" HorizontalAlign="Right" />
                  <SelectedRowStyle BackColor="#738A9C" Font-Bold="True" ForeColor="#F7F7F7" />
                  <HeaderStyle BackColor="#4A3C8C" Font-Bold="True" ForeColor="#F7F7F7" />
                  <AlternatingRowStyle BackColor="#F7F7F7" />
            </asp:GridView>
<asp:SqlDataSource ID="SqlDataSource1" runat="server" 
		ConnectionString="<%$ ConnectionStrings:SuggestionsConnectionString %>" 
		DeleteCommand="DELETE FROM [Ideas] WHERE [SuggestionID] = @SuggestionID" 
		InsertCommand="INSERT INTO [Ideas] ([LastName], [FirstName], [EmailAddress], [SuggestionDate], [Location], [Summary], [Suggestion], [Goal], [HowToAchieve], [CostSavings], [SupportingDocs], [Attachment], [SubmittedDate], [Approved], [DecisionDate], [Comments], [AwardGiven], [AwardAmount], [EstCostSavings], [ReviewedBy]) VALUES (@LastName, @FirstName, @EmailAddress, @SuggestionDate, @Location, @Summary, @Suggestion, @Goal, @HowToAchieve, @CostSavings, @SupportingDocs, @Attachment, @SubmittedDate, @Approved, @DecisionDate, @Comments, @AwardGiven, @AwardAmount, @EstCostSavings, @ReviewedBy)" 
		SelectCommand="SELECT * FROM [Ideas] ORDER BY [SuggestionID]" 
		UpdateCommand="UPDATE [Ideas] SET [LastName] = @LastName, [FirstName] = @FirstName, [EmailAddress] = @EmailAddress, [SuggestionDate] = @SuggestionDate, [Location] = @Location, [Summary] = @Summary, [Suggestion] = @Suggestion, [Goal] = @Goal, [HowToAchieve] = @HowToAchieve, [CostSavings] = @CostSavings, [SupportingDocs] = @SupportingDocs, [Attachment] = @Attachment, [SubmittedDate] = @SubmittedDate, [Approved] = @Approved, [DecisionDate] = @DecisionDate, [Comments] = @Comments, [AwardGiven] = @AwardGiven, [AwardAmount] = @AwardAmount, [EstCostSavings] = @EstCostSavings, [ReviewedBy] = @ReviewedBy WHERE [SuggestionID] = @SuggestionID">
		<DeleteParameters>
			<asp:Parameter Name="SuggestionID" Type="Int32" />
		</DeleteParameters>
		<UpdateParameters>
			<asp:Parameter Name="LastName" Type="String" />
			<asp:Parameter Name="FirstName" Type="String" />
			<asp:Parameter Name="EmailAddress" Type="String" />
			<asp:Parameter Name="SuggestionDate" Type="String" />
			<asp:Parameter Name="Location" Type="String" />
			<asp:Parameter Name="Summary" Type="String" />
			<asp:Parameter Name="Suggestion" Type="String" />
			<asp:Parameter Name="Goal" Type="String" />
			<asp:Parameter Name="HowToAchieve" Type="String" />
			<asp:Parameter Name="CostSavings" Type="String" />
			<asp:Parameter Name="SupportingDocs" Type="String" />
			<asp:Parameter Name="Attachment" Type="String" />
			<asp:Parameter Name="SubmittedDate" Type="String" />
			<asp:Parameter Name="Approved" Type="Boolean" />
			<asp:Parameter Name="DecisionDate" Type="String" />
			<asp:Parameter Name="Comments" Type="String" />
			<asp:Parameter Name="AwardGiven" Type="Boolean" />
			<asp:Parameter Name="AwardAmount" Type="String" />
			<asp:Parameter Name="EstCostSavings" Type="String" />
			<asp:Parameter Name="ReviewedBy" Type="String" />
			<asp:Parameter Name="SuggestionID" Type="Int32" />
		</UpdateParameters>
		<InsertParameters>
			<asp:Parameter Name="LastName" Type="String" />
			<asp:Parameter Name="FirstName" Type="String" />
			<asp:Parameter Name="EmailAddress" Type="String" />
			<asp:Parameter Name="SuggestionDate" Type="String" />
			<asp:Parameter Name="Location" Type="String" />
			<asp:Parameter Name="Summary" Type="String" />
			<asp:Parameter Name="Suggestion" Type="String" />
			<asp:Parameter Name="Goal" Type="String" />
			<asp:Parameter Name="HowToAchieve" Type="String" />
			<asp:Parameter Name="CostSavings" Type="String" />
			<asp:Parameter Name="SupportingDocs" Type="String" />
			<asp:Parameter Name="Attachment" Type="String" />
			<asp:Parameter Name="SubmittedDate" Type="String" />
			<asp:Parameter Name="Approved" Type="Boolean" />
			<asp:Parameter Name="DecisionDate" Type="String" />
			<asp:Parameter Name="Comments" Type="String" />
			<asp:Parameter Name="AwardGiven" Type="Boolean" />
			<asp:Parameter Name="AwardAmount" Type="String" />
			<asp:Parameter Name="EstCostSavings" Type="String" />
			<asp:Parameter Name="ReviewedBy" Type="String" />
		</InsertParameters>
	</asp:SqlDataSource>

Open in new window

0
Comment
Question by:megnin
  • 2
3 Comments
 
LVL 25

Accepted Solution

by:
apeter earned 2000 total points
ID: 23584908
Hope below sample will help u. Use XXX_RowUpdated method to see where there any errors happened while updating.

http://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.gridview.rowupdated.aspx
0
 
LVL 1

Author Comment

by:megnin
ID: 23585099
I'm not sure exactly why, but if GridView.DataBind() is in the Page_Load event it causes the Updates not to happen.

In searching for solutions in other posts I found one that mentioned that.  I removed the GridView1.DataBind() from the Page_Load event and the Updates are working again.  There seems to be a whole bunch of these little things that will make a GridView not work.  I'm stumbling on them one by one.  ;-)
0
 
LVL 1

Author Comment

by:megnin
ID: 23585648
&!%@$! I figured, "Great, that's solved I can start working on the rest of the page now."

So, I put a DetailsView on the page under the GridView with a new SqlDataSource and linked the DetailsView to the SelectedItem in the GridView.

Now the DetailsView won't Update.  I change the data, click Update and it keeps the old data. Piece of (1JF.!
0

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

An alternative to the "For XML" way of pivoting and concatenating result sets into strings, and an easy introduction to "common table expressions" (CTEs). Being someone who is always looking for alternatives to "work your data", I came across this …
This month, Experts Exchange sat down with resident SQL expert, Jim Horn, for an in-depth look into the makings of a successful career in SQL.
Using examples as well as descriptions, and references to Books Online, show the documentation available for datatypes, explain the available data types and show how data can be passed into and out of variables.
Viewers will learn how to use the INSERT statement to insert data into their tables. It will also introduce the NULL statement, to show them what happens when no value is giving for any given column.
Suggested Courses

564 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question