locked
Problem Updating GridView Solved! May Help You... RRS feed

  • Question

  • User-2066415806 posted

    This had me stumped and frustrated for awhile but I finally figured it out.

    My GridView was not updating like so many others have been having problems with, I searched the forums and implemented all the suggestions to fix it to no avail.  To start out, I'm using VS 2005, I have a page set up with a gridview and my datasource is Access.  Everything was displaying fine but the updates were not taking hold, all my parameters were in place and in the proper order.  I actually had two pages in the site with gridviews connected to the same .mdb datasource but different tables.  One worked fine, the other didn't...so this made it fairly easy to troubleshoot. Getting to the point...

    I was missing a critcal property in my GridView tag....DataKeyNames=My Primary Key Field

    <asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" CellPadding="4" DataKeyNames="ID"  DataSourceID="AccessDataSource2" ForeColor="#333333" GridLines="None" AllowPaging="True" AllowSorting="True" PageSize="20">

    My working table had this property because I brought it in from the Server Explorer which automatically created the gridview and had the property set in the GridView tag.  My non-working table was added from the ToolBox and never created this DataKeyNames property in the tag. 

    How was I supposed to know it needed to be there?  Well, I know now!

    Hope this will help someone, I see alot of posts about tables not updating and this was my fix. 

    Wednesday, July 12, 2006 11:23 AM

All replies

  • User727442358 posted

    Right on.  I got the solution just following this post.  Yes, I too missed DataKeyNames (as I needed to add one more parameter, I added every where except in DataKeyNames).  Well, I too know now!.

    Thank you

    Sudar

    Tuesday, May 18, 2010 12:28 PM
  • User727442358 posted

    Right on.  I got the solution just by following this post.  Yes, I too missed DataKeyNames (as I needed to add one more parameter, I added every where except in DataKeyNames).  Well, I too know now!.

    Thank you

    Sudar

    Tuesday, May 18, 2010 12:28 PM