Wrox Programmer Forums
Go Back   Wrox Programmer Forums > ASP.NET and ASP > ASP.NET 4.5 > BOOK: Beginning ASP.NET 4.5 : in C# and VB
BOOK: Beginning ASP.NET 4.5 : in C# and VB
This is the forum to discuss the Wrox book Beginning ASP.NET 4.5: in C# and VB by Imar Spaanjaars; ISBN: 978-1-118-31180-6
Welcome to the p2p.wrox.com Forums.

You are currently viewing the BOOK: Beginning ASP.NET 4.5 : in C# and VB section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
Old January 20th, 2015, 05:27 PM
Authorized User
Join Date: Aug 2014
Posts: 34
Thanks: 3
Thanked 0 Times in 0 Posts
Default unable to update database from GridView Edit/Update

Hi and TIA:

Have looked at a lot of code and tried many of them to no avail.

I am wanting to allow my users to Edit/Update certain columns of my GridView. Using debug, my variable values look good, but SaveChanges() just doesn't seem to do the job. No errors and I do return from edit mode, but the database table remains the same and the GridView textbox reverts back to old value. Any help would be appreciated.

 protected void Page_Load(object sender, EventArgs e)
       if (!IsPostBack)
 protected void GridView1_RowEditing(object sender, GridViewEditEventArgs e)

        GridView1.EditIndex = e.NewEditIndex;

    }//end method GridView1_RowEditing
and finally,

 protected void GridView1_RowUpdating(object sender, GridViewUpdateEventArgs e)
        GridViewRow currentRow = GridView1.Rows[GridView1.EditIndex];

        currentCourseName = ((TextBox)currentRow.Cells[3].Controls[0]).Text;

        //Get the updated value from GridView
        string currentRating = ((TextBox)currentRow.Cells[4].Controls[0]).Text;
        string currentSlope = ((TextBox)currentRow.Cells[5].Controls[0]).Text;
        string currentCourseID = GridView1.Rows[GridView1.EditIndex].Cells[2].Text;

        theCourseID = Int32.Parse(currentCourseID);
        newRating = float.Parse(currentRating);
        newSlope = Int32.Parse(currentSlope);

        using (GolfDatabaseEntities10 myEntities = new GolfDatabaseEntities10())
            Course obj = myEntities.Courses.First(courseSelected => courseSelected.Course_ID == theCourseID);

            //Should set the values in the table Course
            obj.Course_Rating = newRating;
            obj.Course_Slope = newSlope;
            obj.Course_Name = currentCourseName;
            //Save all changes
            //leave edit mode
            GridView1.EditIndex = -1;


        }//end using
    }//end method GridView1_RowUpdating
Old January 23rd, 2015, 06:16 PM
Imar's Avatar
Wrox Author
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts

Hi there,

Have you tried debugging the code and stepping through it? Maybe it's throwing an error somewhere that you don't see?

Imar Spaanjaars
Follow me on Twitter

Author of Beginning ASP.NET 4.5 : in C# and VB, Beginning ASP.NET Web Pages with WebMatrix
and Beginning ASP.NET 4 : in C# and VB.
Did this post help you? Click the button below this post to show your appreciation!

Similar Threads
Thread Thread Starter Forum Replies Last Post
how to update Existing imag in Edit Mode. i can insert easily but unable to Edit. :'( Mail2vasid BOOK: Beginning ASP.NET 4.5 : in C# and VB 9 August 21st, 2014 10:53 AM
unable to update remote access database wrigleo ASP.NET 3.5 Basics 3 July 15th, 2009 06:11 PM
unable to update MySQL database with ASP don baroo Classic ASP Databases 7 November 22nd, 2004 01:22 PM
Unable to update database on server senthilpr_in Access ASP 1 September 23rd, 2003 11:43 PM
Unable to update database on server senthilpr_in Classic ASP Databases 0 September 8th, 2003 04:32 PM

Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.