473,378 Members | 1,577 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,378 software developers and data experts.

GridView: Empty OldValues, NewValues

I ran into a situation this morning where the RowUpdating event of a GridView kept insisting there were no entries in either the
OldValues or NewValues dictionaries. The GridView is bound to a strongly-typed collection, derived from CollectionBase, through the
control's datasource property at runtime.

From some googling it appears that, at least in the release candidate for NET2 this was a known bug; only binding to DataSources
lets those dictionaries be populated.

I would like to confirm that this is a problem with the released version of NET2, so I can stop beating my head against the wall
trying to get the GridView to work "as advertised".

- Mark
Jan 19 '06 #1
5 8333
Hi Mark,

Welcome.
As for the GridView control doesn't correctly populate the OldValues or
NewValues parameters collection when performing udpdate operation, I think
it is likely caused by some certain setting in the GridView control... How
are you binding the data columns from datasource, through the BoundField or
template fields with customized html ? Also, if convenient, would you post
some detailed code snippet of your page and the code behind on this?

Regards,

Steven Cheng
Microsoft Online Support

Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)

--------------------
| NNTP-Posting-Date: Thu, 19 Jan 2006 11:30:35 -0600
| From: Mark Olbert <Ch*********@newsgroups.nospam>
| Newsgroups: microsoft.public.dotnet.framework.aspnet
| Subject: GridView: Empty OldValues, NewValues
| Date: Thu, 19 Jan 2006 09:30:35 -0800
| Organization: Olbert & McHugh, LLC
| Reply-To: ma**@arcabama.com
| Message-ID: <tu********************************@4ax.com>
| X-Newsreader: Forte Agent 3.1/32.783
| MIME-Version: 1.0
| Content-Type: text/plain; charset=us-ascii
| Content-Transfer-Encoding: 7bit
| Lines: 11
| X-Trace:
sv3-WkraMt184xGJ5kKuM+MN7jXAQ3sJZ047pA4gc7dSpEk9As0t2A 6rYev/3ngnBCYGgIVoYshZ
Q/6LIxG!/huEpQjZU2s9w5B2InL9xgsGcFvt8BccxygjubQCbFGN8te4yJQ 886hq/wdXnIvPGeIV
Mg==
| X-Complaints-To: ab***@giganews.com
| X-DMCA-Notifications: http://www.giganews.com/info/dmca.html
| X-Abuse-and-DMCA-Info: Please be sure to forward a copy of ALL headers
| X-Abuse-and-DMCA-Info: Otherwise we will be unable to process your
complaint properly
| X-Postfilter: 1.3.32
| Path:
TK2MSFTNGXA02.phx.gbl!TK2MSFTNGP08.phx.gbl!newsfee d00.sul.t-online.de!t-onli
ne.de!border2.nntp.dca.giganews.com!border1.nntp.d ca.giganews.com!nntp.gigan
ews.com!local01.nntp.dca.giganews.com!news.giganew s.com.POSTED!not-for-mail
| Xref: TK2MSFTNGXA02.phx.gbl
microsoft.public.dotnet.framework.aspnet:372150
| X-Tomcat-NG: microsoft.public.dotnet.framework.aspnet
|
| I ran into a situation this morning where the RowUpdating event of a
GridView kept insisting there were no entries in either the
| OldValues or NewValues dictionaries. The GridView is bound to a
strongly-typed collection, derived from CollectionBase, through the
| control's datasource property at runtime.
|
| From some googling it appears that, at least in the release candidate for
NET2 this was a known bug; only binding to DataSources
| lets those dictionaries be populated.
|
| I would like to confirm that this is a problem with the released version
of NET2, so I can stop beating my head against the wall
| trying to get the GridView to work "as advertised".
|
| - Mark
|

Jan 20 '06 #2
Steven,

From the aspx file:

<asp:GridView ID="gridCart" runat="server" AutoGenerateColumns="False" CellPadding="2" CellSpacing="2" AllowPaging="True"
EmptyDataText="the cart is empty" OnPageIndexChanging="gridCart_PageIndexChanging" OnRowCancelingEdit="gridCart_RowCancelingEdit"
OnRowDeleting="gridCart_RowDeleting" OnRowEditing="gridCart_RowEditing" OnRowUpdating="gridCart_RowUpdating">
<Columns>
<asp:BoundField DataField="ProductName" HeaderText="Product" ReadOnly="True" />
<asp:BoundField DataField="Quantity" HeaderText="Quantity" DataFormatString="{0:n}" >
<ItemStyle HorizontalAlign="Right" />
</asp:BoundField>
<asp:BoundField DataField="UnitPrice" DataFormatString="{0:c2}" HeaderText="Unit Price" ReadOnly="True" >
<ItemStyle HorizontalAlign="Right" />
</asp:BoundField>
<asp:BoundField DataField="Price" DataFormatString="{0:C2}" HeaderText="Price" ReadOnly="True" >
<ItemStyle HorizontalAlign="Right" />
</asp:BoundField>
<asp:CommandField ShowEditButton="True" />
<asp:CommandField ShowDeleteButton="True" />
</Columns>
</asp:GridView>

From the aspx.cs file in Page_Load:

if( !Page.IsPostBack )
{
gridCart.DataSource = SiteInfo.Cart;
gridCart.DataBind();
}

- Mark
Jan 20 '06 #3
Hi Mark,

Thanks for your response and the code you provided, so you're using a
custom class collection without using any DataSource control, I think this
should be the cause of the parameters collection in RowUpdating event being
empty. All the parameters are actually associated to the Parameters
declared in DataSource control (the select and update statement in
DataSource control), also we can find some parameter name related attribute
such as

OldValuesParameterFormatString="original_{0}"

So when we do not using DataSource control, there is no info for populating
named parameters .... Thus, we may have to use the original means that
extract the value from GridViewRow's Cell control collection like what we
done in asp.net 1.1 with datagrid...

Regards,

Steven Cheng
Microsoft Online Support

Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)
--------------------
| NNTP-Posting-Date: Fri, 20 Jan 2006 09:16:01 -0600
| From: Mark Olbert <Ch*********@newsgroups.nospam>
| Newsgroups: microsoft.public.dotnet.framework.aspnet
| Subject: Re: GridView: Empty OldValues, NewValues
| Date: Fri, 20 Jan 2006 07:16:09 -0800
| Organization: Olbert & McHugh, LLC
| Reply-To: ma**@arcabama.com
| Message-ID: <pg********************************@4ax.com>
| References: <tu********************************@4ax.com>
<BK**************@TK2MSFTNGXA02.phx.gbl>
| X-Newsreader: Forte Agent 3.1/32.783
| MIME-Version: 1.0
| Content-Type: text/plain; charset=us-ascii
| Content-Transfer-Encoding: 7bit
| Lines: 32
| X-Trace:
sv3-LAZYmdBolYhx+kJpAmoBOGULDT2IaOt8mm0XAdS3/H8Wolx8XkjG2EjqyINMBt07V7vW05b7
BZLOjiS!+eHmPdzx7M/uknFZJOhFDbJ5W5f40+9WyC2ZrYcAVcbqV8rb5BTKgyj724PJ7 ARmnbYG
EQ==
| X-Complaints-To: ab***@giganews.com
| X-DMCA-Notifications: http://www.giganews.com/info/dmca.html
| X-Abuse-and-DMCA-Info: Please be sure to forward a copy of ALL headers
| X-Abuse-and-DMCA-Info: Otherwise we will be unable to process your
complaint properly
| X-Postfilter: 1.3.32
| Path:
TK2MSFTNGXA02.phx.gbl!TK2MSFTNGP08.phx.gbl!newsfee d00.sul.t-online.de!t-onli
ne.de!news.glorb.com!postnews.google.com!news3.goo gle.com!border1.nntp.dca.g
iganews.com!nntp.giganews.com!local01.nntp.dca.gig anews.com!news.giganews.co
m.POSTED!not-for-mail
| Xref: TK2MSFTNGXA02.phx.gbl
microsoft.public.dotnet.framework.aspnet:372406
| X-Tomcat-NG: microsoft.public.dotnet.framework.aspnet
|
| Steven,
|
| From the aspx file:
|
| <asp:GridView ID="gridCart" runat="server" AutoGenerateColumns="False"
CellPadding="2" CellSpacing="2" AllowPaging="True"
| EmptyDataText="the cart is empty"
OnPageIndexChanging="gridCart_PageIndexChanging"
OnRowCancelingEdit="gridCart_RowCancelingEdit"
| OnRowDeleting="gridCart_RowDeleting" OnRowEditing="gridCart_RowEditing"
OnRowUpdating="gridCart_RowUpdating">
| <Columns>
| <asp:BoundField DataField="ProductName" HeaderText="Product"
ReadOnly="True" />
| <asp:BoundField DataField="Quantity" HeaderText="Quantity"
DataFormatString="{0:n}" >
| <ItemStyle HorizontalAlign="Right" />
| </asp:BoundField>
| <asp:BoundField DataField="UnitPrice" DataFormatString="{0:c2}"
HeaderText="Unit Price" ReadOnly="True" >
| <ItemStyle HorizontalAlign="Right" />
| </asp:BoundField>
| <asp:BoundField DataField="Price" DataFormatString="{0:C2}"
HeaderText="Price" ReadOnly="True" >
| <ItemStyle HorizontalAlign="Right" />
| </asp:BoundField>
| <asp:CommandField ShowEditButton="True" />
| <asp:CommandField ShowDeleteButton="True" />
| </Columns>
| </asp:GridView>
|
| From the aspx.cs file in Page_Load:
|
| if( !Page.IsPostBack )
| {
| gridCart.DataSource = SiteInfo.Cart;
| gridCart.DataBind();
| }
|
| - Mark
|

Jan 23 '06 #4
Steven,

Thanx for confirming the limitation. Two things:

1) I think this needs to be documented better. I don't recall seeing it emphasized in the documentation, and these kinds of
dependencies create annoying bugs.

2) I think it's weird that the "value" capability is tied to the parameters collection. Why not the field collection, instead? That
way it'd work with both types of data binding.

- Mark
Jan 23 '06 #5
Thanks for your followup Mark,

Frankly speeking, I do agree with you that this is a big limitation since I
haven't noticed this before until you mentioned this...
Anyway, you can also add the suggestion on the MSDN feedback center. Also,
I think it'll still require us to use DataSource Control when we need to
Updating event to contains Parameters collection, however, it may become
more user friendly if there're some additional functions on the DataBound
control which can help extract bound values from each row /column...

Thanks for your understanding...

Steven Cheng
Microsoft Online Support

Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)
--------------------
| NNTP-Posting-Date: Mon, 23 Jan 2006 11:00:13 -0600
| From: Mark Olbert <Ch*********@newsgroups.nospam>
| Newsgroups: microsoft.public.dotnet.framework.aspnet
| Subject: Re: GridView: Empty OldValues, NewValues
| Date: Mon, 23 Jan 2006 09:00:13 -0800
| Organization: Olbert & McHugh, LLC
| Reply-To: ma**@arcabama.com
| Message-ID: <ho********************************@4ax.com>
| References: <tu********************************@4ax.com>
<BK**************@TK2MSFTNGXA02.phx.gbl>
<pg********************************@4ax.com>
<Rx**************@TK2MSFTNGXA02.phx.gbl>
| X-Newsreader: Forte Agent 3.1/32.783
| MIME-Version: 1.0
| Content-Type: text/plain; charset=us-ascii
| Content-Transfer-Encoding: 7bit
| Lines: 11
| X-Trace:
sv3-U9nK6TomeE9bhjkWeXcn08zAR1rLXufi10YwNgyd0i3SWgCu++ zPjD1xg6GVJGAbK7Dnh2WO
bVwtOgT!haAJ9ZncP8Ei3q+L2+nGKN1K6B5U57An5wPDTlBfTR hgocD5IBPrxek8OkQ6ARdran47
nw==
| X-Complaints-To: ab***@giganews.com
| X-DMCA-Notifications: http://www.giganews.com/info/dmca.html
| X-Abuse-and-DMCA-Info: Please be sure to forward a copy of ALL headers
| X-Abuse-and-DMCA-Info: Otherwise we will be unable to process your
complaint properly
| X-Postfilter: 1.3.32
| Path:
TK2MSFTNGXA02.phx.gbl!TK2MSFTNGP08.phx.gbl!newsfee d00.sul.t-online.de!t-onli
ne.de!border2.nntp.dca.giganews.com!border1.nntp.d ca.giganews.com!nntp.gigan
ews.com!local01.nntp.dca.giganews.com!news.giganew s.com.POSTED!not-for-mail
| Xref: TK2MSFTNGXA02.phx.gbl
microsoft.public.dotnet.framework.aspnet:372922
| X-Tomcat-NG: microsoft.public.dotnet.framework.aspnet
|
| Steven,
|
| Thanx for confirming the limitation. Two things:
|
| 1) I think this needs to be documented better. I don't recall seeing it
emphasized in the documentation, and these kinds of
| dependencies create annoying bugs.
|
| 2) I think it's weird that the "value" capability is tied to the
parameters collection. Why not the field collection, instead? That
| way it'd work with both types of data binding.
|
| - Mark
|

Jan 24 '06 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Amelyan | last post by:
I seem to have a problem using VS2005 GridView. When I tried to implement RowUpdating or RowUpdated handlers NewValues, OldValues, and AllKeys collecitons are empty. Also, when I tried to...
0
by: Michael | last post by:
Hi I'm having a problem getting the newvalues or oldvalues from the RowUpdating event. I have the following code for the event(See note): Protected Sub grdPOs_RowUpdating(ByVal sender As Object,...
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...
3
by: Just Me | last post by:
Im struggling a bit with the update function. I have bound a table with lets say 5 records ( 4 columns ) to the gridview , this displays jsut fine. I have added edit/cancel/update buttons in a...
9
by: Mel | last post by:
I have 10 columns total. 3 of them are invisible. The rest are read- only BoundFields, 3 of which are editable fields using TemplateFields. Upon editing, I want to validate what the user enters...
4
by: anniebai | last post by:
Please help me with writing a RowUpdating function in C#, I don't know how to grab the current field's value and also get the old value for one of keys (which is ProjectName for editing) of the...
0
by: lightgram | last post by:
Hello I am having problems extracting the OldValues collection from the RowUpdating event in my GridView. Every time I access this I am getting the values from the NewValues collection in...
6
by: =?Utf-8?B?UGF1bA==?= | last post by:
Hi I have a gridview control with a template column that has a textbox and when the control is bound to the datasource the textbox is filled ok. I then change what is in the textbox in 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
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
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: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
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.