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. -
<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False">
-
<Columns>
-
<asp:CommandField ShowEditButton="True" />
-
<asp:BoundField DataField="PERSON_ID" HeaderText="ID" />
-
<asp:BoundField DataField="YEAR" HeaderText="Year" />
-
</Columns>
-
</asp:GridView>
-
'in code behind -
Private Sub BindGrid()
-
GridView1.DataSource = GetData(iID, iYear)
-
GridView1.DataBind()
-
End Sub
-
-
-
Protected Sub GridView1_RowEditing(ByVal sender As Object, ByVal e As GridViewEditEventArgs) Handles GridView1.RowEditing
-
GridView1.EditIndex = e.NewEditIndex
-
BindGrid()
-
End Sub
-
-
Protected Sub GridView1_RowUpdating(ByVal sender As Object, ByVal e As GridViewUpdateEventArgs) Handles GridView1.RowUpdating
-
'handle Update here
-
End Sub
-
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. -
<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False">
-
<Columns>
-
<asp:CommandField ShowEditButton="True" />
-
<asp:BoundField DataField="PERSON_ID" HeaderText="ID" />
-
<asp:BoundField DataField="YEAR" HeaderText="Year" />
-
</Columns>
-
</asp:GridView>
-
'in code behind -
Private Sub BindGrid()
-
GridView1.DataSource = GetData(iID, iYear)
-
GridView1.DataBind()
-
End Sub
-
-
-
Protected Sub GridView1_RowEditing(ByVal sender As Object, ByVal e As GridViewEditEventArgs) Handles GridView1.RowEditing
-
GridView1.EditIndex = e.NewEditIndex
-
BindGrid()
-
End Sub
-
-
Protected Sub GridView1_RowUpdating(ByVal sender As Object, ByVal e As GridViewUpdateEventArgs) Handles GridView1.RowUpdating
-
'handle Update here
-
End Sub
-
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
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.
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
Frinny, it was a post-back, binding issue after all! Thanks for your reply.
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!!!
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
Check if you have put any validators on your page. Because the page will not go for post back until all validators are validated.
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. - <asp:CommandField ShowEditButton="true" ButtonType="Link"
-
CausesValidation="false" />
For others with this issue, try: - Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
-
If Not Me.IsPostBack Then
-
GridView.DataSource = DataSource1
-
GridView.DataBind()
-
End If[/indent]End Sub
Sign in to post your reply or Sign up for a free account.
Similar topics |
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
|
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
|
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"
|
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?
|
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
| |
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
|
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!
|
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.
|
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:
|
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...
|
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,...
| |
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...
|
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,...
|
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...
|
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();...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |
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...
| |