473,372 Members | 1,036 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,372 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 26814
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

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

Similar topics

7
by: Programatix | last post by:
Hi, I'm working on a WebService project. I'm trying to validate data before they are updated to the database by handling the RowUpdating event for a SqlDataAdapter. The data being handled has...
28
by: Tim_Mac | last post by:
hi, i'm new to .net 2.0, and am just starting to get to grips with the gridview. my page has autoEventWireUp set to true, which i gather is supposed to figure out which handlers to invoke when...
1
by: bill | last post by:
I have an update panel that contains a gridview. There are 2 triggers: one for a search button that is outside the panel and one for the gridview EditCommand Event. The search works fine, the...
13
by: AG | last post by:
I have a gridview that I bind to a List(of Type) at runtime. Not using a datasource control. The gridview has a template column with an imagebutton whose commandname is set to 'Delete'. The...
3
by: slemen | last post by:
The controls (textboxes) in the gridview row being updated have the old, pre user updated values in the RowUpdating event. Does anyone have an idea why? Thank you, Scott
1
by: s.bussing | last post by:
Hi, I have been struggling with the GridView the whole day, but can not get this solved. The rowupdating event in my Gridview doesn't give me the new values only the old ones. In my GridView I...
1
by: Steve Kershaw | last post by:
Hi, I'm using the RowUpdating() event of an updatable GridView. I need to see the values of the columns in the updated row. There has got to be a way to do this! Any suggestions? Thanks...
3
by: nick chan | last post by:
Hi i run into some difficulties getting rowupdating to fire when clicking Update link/button on gridview I set datasource at runtime, basically a datatable Edit and Cancel works. I don't know...
0
by: E. Kwong | last post by:
In a Gridview control, I have several BoundFields, and also a couple of TemplateFields. In the Rowupdating event, I try to retrieve one of the BoundFields (i.e. 4th column of the Gridview...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

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.