472,143 Members | 1,299 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,143 software developers and data experts.

GridView RowUpdating event not firing

I am using a SQLDataSource to populate my gridview in ASP.Net 2.0. When I hit Edit, the textboxes appear and I am able to edit my values. When I hit Update, the changes are not saved, and there is no error message. I put a breakpoint on the RowUpdating event handler and found that the event is not fired. Right now, I have not written code for the Update event. I am just wondering why the event is not firing. Here Person_ID is the primary key. Please help. Thanks.
Expand|Select|Wrap|Line Numbers
  1. <asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False">
  2. <Columns>
  3. <asp:CommandField ShowEditButton="True" />
  4. <asp:BoundField DataField="PERSON_ID" HeaderText="ID" />
  5. <asp:BoundField DataField="YEAR" HeaderText="Year" />
  6. </Columns>
  7. </asp:GridView>
  8.  
'in code behind
Expand|Select|Wrap|Line Numbers
  1.  Private Sub BindGrid()
  2.  GridView1.DataSource = GetData(iID, iYear)
  3.  GridView1.DataBind()
  4.  End Sub
  5.  
  6.  
  7. Protected Sub GridView1_RowEditing(ByVal sender As Object, ByVal e As GridViewEditEventArgs) Handles GridView1.RowEditing
  8. GridView1.EditIndex = e.NewEditIndex
  9. BindGrid()
  10. End Sub
  11.  
  12. Protected Sub GridView1_RowUpdating(ByVal sender As Object, ByVal e As GridViewUpdateEventArgs) Handles GridView1.RowUpdating
  13. 'handle Update here
  14. End Sub
  15.  
May 15 '07 #1
9 26600
Frinavale
9,735 Expert Mod 8TB
I am using a SQLDataSource to populate my gridview in ASP.Net 2.0. When I hit Edit, the textboxes appear and I am able to edit my values. When I hit Update, the changes are not saved, and there is no error message. I put a breakpoint on the RowUpdating event handler and found that the event is not fired. Right now, I have not written code for the Update event. I am just wondering why the event is not firing. Here Person_ID is the primary key. Please help. Thanks.
Expand|Select|Wrap|Line Numbers
  1. <asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False">
  2. <Columns>
  3. <asp:CommandField ShowEditButton="True" />
  4. <asp:BoundField DataField="PERSON_ID" HeaderText="ID" />
  5. <asp:BoundField DataField="YEAR" HeaderText="Year" />
  6. </Columns>
  7. </asp:GridView>
  8.  
'in code behind
Expand|Select|Wrap|Line Numbers
  1.  Private Sub BindGrid()
  2.  GridView1.DataSource = GetData(iID, iYear)
  3.  GridView1.DataBind()
  4.  End Sub
  5.  
  6.  
  7. Protected Sub GridView1_RowEditing(ByVal sender As Object, ByVal e As GridViewEditEventArgs) Handles GridView1.RowEditing
  8. GridView1.EditIndex = e.NewEditIndex
  9. BindGrid()
  10. End Sub
  11.  
  12. Protected Sub GridView1_RowUpdating(ByVal sender As Object, ByVal e As GridViewUpdateEventArgs) Handles GridView1.RowUpdating
  13. 'handle Update here
  14. End Sub
  15.  
Did you put the break point at line 12 in the "code behind"?
I see no reason why this would not fire.

You cannot put a break point inside that function because there is nothing to break on.

-Frinny
May 15 '07 #2
Thanks for your reply.

Yes, I did put the breakpoint at the RowUpdating line (and not in the function). In the RowEditing function, the edit textboxes appear and I can get the "old" values Then the page renders, I edit the textboxes and hit Update. Then the page posts back, the text boxes go back to being labels and the new values are lost, and the RowUpdating code never fires.
May 15 '07 #3
Frinavale
9,735 Expert Mod 8TB
Thanks for your reply.

Yes, I did put the breakpoint at the RowUpdating line (and not in the function). In the RowEditing function, the edit textboxes appear and I can get the "old" values Then the page renders, I edit the textboxes and hit Update. Then the page posts back, the text boxes go back to being labels and the new values are lost, and the RowUpdating code never fires.

You have to make sure that you aren't setting your GridView's data when it is not postback. If you do this, your GridView's source will be refreshed before you're able to grab the new values out of it.

I'm having a very hard time understand what would prevent your event from being fired. Do you have some sort of JavaScript functionality that may be stopping it?

-Frinny
May 15 '07 #4
Frinny, it was a post-back, binding issue after all! Thanks for your reply.
May 16 '07 #5
jcp001
1
Hi all,

I seem to be having the same issue but I don't quite follow the trouble with the above post. Sorry, I'm a newbie on this application. Can you explain the T/S a little more or maybe point me to another post that may have already covered it?

Any help would greatly be appreciated!!!
May 18 '07 #6
Frinavale
9,735 Expert Mod 8TB
Hi all,

I seem to be having the same issue but I don't quite follow the trouble with the above post. Sorry, I'm a newbie on this application. Can you explain the T/S a little more or maybe point me to another post that may have already covered it?

Any help would greatly be appreciated!!!
Hi JCP!

A common problem people have with GridViews is understanding when to data bind the data source to the GridView.

It's quite common that people create the data source and bind this source to the GridView in their Page_Load() method.

What happens with this is that the source is being created every time the user submits the page.

This means that when the user does an update, the data from that update is lost.

You should create your data source once (on the user's first visit) and store it into Session for later use, and only bind the GridView to the data source when it is necessary to do so.

I would recommend trying this out and starting a new thread in the .NET Forum so that other people can learn from the experience too.

:)

Cheers!

-Frinny
May 18 '07 #7
Check if you have put any validators on your page. Because the page will not go for post back until all validators are validated.
Jul 18 '08 #8
You may need to turn off validation even if you are not validating anything. It seems like the JavaScript can get mangled otherwise.

If you are using command buttons, then do not use AutoGenerateEditButton.

Expand|Select|Wrap|Line Numbers
  1. <asp:CommandField ShowEditButton="true" ButtonType="Link" 
  2. CausesValidation="false" />
Aug 4 '08 #9
For others with this issue, try:

Expand|Select|Wrap|Line Numbers
  1. Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
  2.     If Not Me.IsPostBack Then
  3.        GridView.DataSource = DataSource1
  4.        GridView.DataBind()
  5.     End If[/indent]End Sub
Jul 12 '10 #10

Post your reply

Sign in to post your reply or Sign up for a free account.

Similar topics

13 posts views Thread by AG | last post: by
3 posts views Thread by slemen | last post: by
3 posts views Thread by nick chan | last post: by
reply views Thread by leo001 | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.