473,796 Members | 2,720 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

GridView RowUpdating event not firing

4 New Member
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 26927
Frinavale
9,735 Recognized Expert Moderator Expert
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
John007
4 New Member
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 Recognized Expert Moderator Expert
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
John007
4 New Member
Frinny, it was a post-back, binding issue after all! Thanks for your reply.
May 16 '07 #5
jcp001
1 New Member
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 Recognized Expert Moderator Expert
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
rubin8083
1 New Member
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
smkowalczyk
1 New Member
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 AutoGenerateEdi tButton.

Expand|Select|Wrap|Line Numbers
  1. <asp:CommandField ShowEditButton="true" ButtonType="Link" 
  2. CausesValidation="false" />
Aug 4 '08 #9
jpl0509
1 New Member
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
3155
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 DataRelation which is related to another DataTable. As for that, I also need to retrieve the DataRelation from the current row being updated. I wrote a code which look something like this, Dim relation As DataRelation
28
10279
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 appropriate based on your method names . the GridView has OnRowCommand="GridView1_RowCommand" in the aspx. my problem is that the RowCommand event is firing twice (95% of the time) on the page. the other 5% it only fires once. there's no
1
2250
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 button click event fires, no problem. But the event for the EditCommand does not fire. Any Ideas? Any one else seen this? Here is some code: <cc2:ScriptManager ID="atlasScriptManager" runat="server"
13
42071
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 footer template has an commandbutton with the commandname set to 'Insert'. Both buttons cause postback, however the RowCommand event does not fire. How can I get the rowcommand to fire?
3
9807
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
9015
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 do not use a DataSourceObject and can therefore not use e.NewValues or e.OldValues The columns used are template columns
1
9566
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 in advance!
3
4868
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 why RowUpdating just doesn't fire.
0
2508
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 control) for comparision purpose. However; I got null string everytime. On the other hand, I'm able to retrieve the dropdownbox value in the TemplateField. I would like to know what I did wrong with the BoundField. Thanks. Code fragment:
0
9673
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9524
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10217
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10168
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10003
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
6785
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5568
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
3730
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2924
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.