Click here to Skip to main content
15,870,297 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have a GridView sitting on an ASP.NET web form page using simple update button. You click on the update, can change the data in the fields, then when you click the 'Update' link provided by the control The method which I had constructed and tested doesn't seem to be activated at all.

I built a sub to try and drive this and control the process a bit more, then got off into the woods trying to fix the sub to work. I got the sub working fine but on doing that I found that even though I had a sub working that triggered off the update button in edit mode from the gridview and could verify that the data was there... AND... even went so far as to add code to the sub to initiate what should have been an unnecessary call to update the record, nothing is getting written to the table from the edit.

As I had this working perfectly at one point and then a formatting glitch messed it up I suspect that something has changed in a parameter setting that is inhibiting the update and simply needs to be switch off. I'll post below what I would think was the pertinent information but if you believe there is other information that would be helpful in you helping me please let me know and I will get it to you. Really want this gone from my project list, its been a pain.

Note that the Update Method is using in this example the session variable "DocID" to find the correct record to update. But I've used current index as well for testing with the same results this is simply the current version. I Have no preference either way.

The SQLDataSource reads as:
Quote:
<asp:SqlDataSource ID="GapDocDataSource" runat="server"
ConnectionString="<%$ ConnectionStrings:ARFSConnectionString %>" SelectCommand="SELECT [DocID], [DElement_Sub], [Doc_Name], [ENote], [Doc_Section], [Windows_C], [Windows_G], [Windows_U], [UNIX], [Mainframe], [IDS_IPS], [Network], [Other], [NotApply] FROM [GETT_DocGaps] WHERE ([ARSDocTag] = @ARSDocTag)"
DeleteCommand="DELETE FROM GETT_DocGaps WHERE (DocID= @DocID) "
InsertCommand="INSERT INTO GETT_DocGaps(ARSDocTag, DElement_Sub, Doc_Name, ENote, Doc_Section, Windows_C, Windows_G, Windows_U, UNIX, Mainframe, IDS_IPS, Network, Other, NotApply) VALUES (@ARSDocTag, @DElement_Sub, @Doc_Name, @ENote, @Doc_Section, @Windows_C, @Windows_G, @Windows_U, @UNIX, @Mainframe, @IDS_IPS, @Network, @Other, @NotApply)"
UpdateCommand="UPDATE GETT_DocGaps SET Doc_Name = @Doc_Name, ENote = @ENote, Doc_Section = @Doc_Section, Windows_C = @Windows_C, Windows_G = @Windows_G, Windows_U = @Windows_U, UNIX = @UNIX, Mainframe = @Mainframe, IDS_IPS = @IDS_IPS, Network = @Network, Other = @Other, NotApply = @NotApply WHERE (DocID = @DocID)" ViewStateMode="Enabled">
<deleteparameters>
<asp:Parameter Name="DElement_Sub">
<asp:Parameter Name="ARSDocTag">

<insertparameters>
<asp:Parameter Name="ARSDocTag">
<asp:Parameter Name="DElement_Sub">
<asp:Parameter Name="Doc_Name">

<SelectParameters>
<asp:SessionParameter Name="ARSDocTag" SessionField="ArticleFocus" Type="String" />
</SelectParameters>
<updateparameters>
<asp:SessionParameter Name="Doc_Name" SessionField="DocID" />
<asp:Parameter Name="ENote">
<asp:Parameter Name="Doc_Section">
<asp:Parameter Name="Windows_C">
<asp:Parameter Name="Windows_G">
<asp:Parameter Name="Windows_U">
<asp:Parameter Name="UNIX">
<asp:Parameter Name="Mainframe">
<asp:Parameter Name="IDS_IPS">
<asp:Parameter Name="Network">
<asp:Parameter Name="Other">
<asp:Parameter Name="NotApply">
<asp:Parameter Name="DocID">




Then there is the Sub that handle the process when the update button is clicked during an edit. This shouldn't be needed but I added it just to give me a bit more control and let me see what was going on. This works but doesn't really help at all:
C#
Protected Sub GridView1_RowUpdating(sender As Object, e As GridViewUpdateEventArgs) Handles GridView1.RowUpdating

    Try
        Dim row As GridViewRow = GridView1.Rows(e.RowIndex)   'Get the edit row
        ident = row.Cells(3).Text                             'Get the value. you could set a breakpoint to check the value.
        Session("DocId") = ident                              'Save value in session

        'GapDocDataSource.Update()                             There is no need to call SqlDatabase update Method here

    Catch

    End Try
End Sub



As I said, if you feel screen shots or any other information would be helpful in you helping me let me know and I will do what I can to getting it to you but there are no errors popping up here. It simply is not writing the updates to the database.

Thanks and regards,
Ken...
Posted

 
Share this answer
 
Comments
KC@CahabaGBA 23-Nov-15 8:43am    
Okay I just watched the video after this one and I think you pointed to the source of my problem which is going to be 'DataKeyName'. I'm going to play around with it but in your demonstration you attempting an update but it wasn't updating your table. The cause was not being able to reference the correct row which was corrected by setting the reference with the DatakeyName value. In my case this would be targeting 'DocID' which is my unique identifier in my table.

Think this may have it! Going to go do some testing will follow up once I've had a chance to test.

Thanks & Regards,
Ken...
KC@CahabaGBA 23-Nov-15 11:23am    
Please Note in Tarun's response this was NOT the actual resolution, however I wanted to be sure to give credit for Tarun providing the direction to the resolution which WAS found in the DataKeyName being included in the GridView tag definition. I had some other minor issues to resolve due to this being such a lingering problem and having so much code manipulated around the issue but the out come was that adding a specific reference of the DataKeyName referencing my unique identifier for my update method 'DocID' resolved this issue. There was mention regarding DataKeyName in the video provided by Tarun following the one he pointed to above. Because of that I wanted to provide full recognition of the contribution to this solution.

Regards and Thanks!
Ken...
I will take a look at this. The code presently is in VB and I would prefer to leave it there as that is where it was to begin with but I don't see any reason why this process wouldn't work with VB as well as C#. I'll be getting to it here in a next hour or so to explore it.

Reading though this it wasn't 100% clear if this was to be performed during Debug or not, but I'll go back and review it prior to attempting it first. Thank you, it is more to go on than I've had to date.

Regards,
Ken...
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900