GridView: Empty OldValues, NewValues

Discussion in 'ASP .Net' started by Mark Olbert, Jan 19, 2006.

  1. Mark Olbert

    Mark Olbert Guest

    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
     
    Mark Olbert, Jan 19, 2006
    #1
    1. Advertising

  2. 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 <>
    | 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:
    | Message-ID: <>
    | 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+MN7jXAQ3sJZ047pA4gc7dSpEk9As0t2A6rYev/3ngnBCYGgIVoYshZ
    Q/6LIxG!/huEpQjZU2s9w5B2InL9xgsGcFvt8BccxygjubQCbFGN8te4yJQ886hq/wdXnIvPGeIV
    Mg==
    | X-Complaints-To:
    | 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!newsfeed00.sul.t-online.de!t-onli
    ne.de!border2.nntp.dca.giganews.com!border1.nntp.dca.giganews.com!nntp.gigan
    ews.com!local01.nntp.dca.giganews.com!news.giganews.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
    |
     
    Steven Cheng[MSFT], Jan 20, 2006
    #2
    1. Advertising

  3. Mark Olbert

    Mark Olbert Guest

    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
     
    Mark Olbert, Jan 20, 2006
    #3
  4. 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 <>
    | 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:
    | Message-ID: <>
    | References: <>
    <>
    | 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+9WyC2ZrYcAVcbqV8rb5BTKgyj724PJ7ARmnbYG
    EQ==
    | X-Complaints-To:
    | 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!newsfeed00.sul.t-online.de!t-onli
    ne.de!news.glorb.com!postnews.google.com!news3.google.com!border1.nntp.dca.g
    iganews.com!nntp.giganews.com!local01.nntp.dca.giganews.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
    |
     
    Steven Cheng[MSFT], Jan 23, 2006
    #4
  5. Mark Olbert

    Mark Olbert Guest

    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
     
    Mark Olbert, Jan 23, 2006
    #5
  6. 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 <>
    | 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:
    | Message-ID: <>
    | References: <>
    <>
    <>
    <>
    | 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+nGKN1K6B5U57An5wPDTlBfTRhgocD5IBPrxek8OkQ6ARdran47
    nw==
    | X-Complaints-To:
    | 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!newsfeed00.sul.t-online.de!t-onli
    ne.de!border2.nntp.dca.giganews.com!border1.nntp.dca.giganews.com!nntp.gigan
    ews.com!local01.nntp.dca.giganews.com!news.giganews.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
    |
     
    Steven Cheng[MSFT], Jan 24, 2006
    #6
  7. Mark Olbert

    jfortier2

    Joined:
    Jul 22, 2006
    Messages:
    1
    bound columns not always getting generated as params

    I suppose it may be related?

    I have been pulling my hair out, because as far as I can tell, there is some randomness in when the grid view does and does not populate the field names for the update statement.

    At one point, I was staring, almost screaming, at a gridview where I had two columns with the same params in my gridview, and one was generating a param and one wasn't (I was testing by editing my UPDATE statement to have various params, to see which were present).

    Eg,


    ...
    <asp:BoundField DataField="stuff1" HeaderText="StuffOne" SortExpression="stuff1" />
    <asp:BoundField DataField="stuff2" HeaderText="StuffTwo" SortExpression="stuff2" />



    and then in my DataSource, I'd try
    SelectCommand="SELECT stuff1, stuff2 from testtable"
    UpdateCommand="EXEC [dbo].[LogTest] @stuff1, 'dummy'"

    and it would work

    but if I changed to


    SelectCommand="SELECT stuff1, stuff2 from testtable"
    UpdateCommand="EXEC [dbo].[LogTest] @stuff2, 'dummy'"

    it would fail with the error that @stuff2 was not defined


    It has been driving me crazy, because there must be a bug causing it to appear to be random when gridview drops columns.

    I tried with both listed in DataKeyNames, and neither listed in DataKeyNames, and that didn't seem to affect things at all (which is also odd).
     
    jfortier2, Jul 22, 2006
    #7
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Replies:
    1
    Views:
    1,070
  2. Marius Manolea
    Replies:
    0
    Views:
    1,045
    Marius Manolea
    Jun 4, 2008
  3. xs8899
    Replies:
    0
    Views:
    812
    xs8899
    May 22, 2009
  4. Doug Kent

    OldValues and NewValues collections are empty

    Doug Kent, Jul 30, 2008, in forum: ASP .Net Web Controls
    Replies:
    4
    Views:
    930
    Doug Kent
    Jul 31, 2008
  5. Doug Kent

    OldValues and NewValues collections are empty

    Doug Kent, Jul 30, 2008, in forum: ASP .Net Web Services
    Replies:
    0
    Views:
    179
    Doug Kent
    Jul 30, 2008
Loading...

Share This Page