By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
443,837 Members | 1,842 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 443,837 IT Pros & Developers. It's quick & easy.

GridView: Empty OldValues, NewValues

P: n/a
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
Share this Question
Share on Google+
5 Replies


P: n/a
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

P: n/a
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

P: n/a
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

P: n/a
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

P: n/a
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 discussion thread is closed

Replies have been disabled for this discussion.