GridView: Empty OldValues, NewValues

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Mark Olbert

    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
  • Steven Cheng[MSFT]

    #2
    RE: GridView: Empty OldValues, NewValues

    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 <ChairmanMAO@ne wsgroups.nospam >
    | Newsgroups: microsoft.publi c.dotnet.framew ork.aspnet
    | Subject: GridView: Empty OldValues, NewValues
    | Date: Thu, 19 Jan 2006 09:30:35 -0800
    | Organization: Olbert & McHugh, LLC
    | Reply-To: mark@arcabama.c om
    | Message-ID: <tuivs1ppk2aud1 ailae8p6cmfcsbm ct7uk@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-WkraMt184xGJ5kK uM+MN7jXAQ3sJZ0 47pA4gc7dSpEk9A s0t2A6rYev/3ngnBCYGgIVoYsh Z
    Q/6LIxG!/huEpQjZU2s9w5B2 InL9xgsGcFvt8Bc cxygjubQCbFGN8t e4yJQ886hq/wdXnIvPGeIV
    Mg==
    | X-Complaints-To: abuse@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.p hx.gbl!TK2MSFTN GP08.phx.gbl!ne wsfeed00.sul.t-online.de!t-onli
    ne.de!border2.n ntp.dca.giganew s.com!border1.n ntp.dca.giganew s.com!nntp.giga n
    ews.com!local01 .nntp.dca.gigan ews.com!news.gi ganews.com.POST ED!not-for-mail
    | Xref: TK2MSFTNGXA02.p hx.gbl
    microsoft.publi c.dotnet.framew ork.aspnet:3721 50
    | X-Tomcat-NG: microsoft.publi c.dotnet.framew ork.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
    |

    Comment

    • Mark Olbert

      #3
      Re: GridView: Empty OldValues, NewValues

      Steven,

      From the aspx file:

      <asp:GridView ID="gridCart" runat="server" AutoGenerateCol umns="False" CellPadding="2" CellSpacing="2" AllowPaging="Tr ue"
      EmptyDataText=" the cart is empty" OnPageIndexChan ging="gridCart_ PageIndexChangi ng" OnRowCancelingE dit="gridCart_R owCancelingEdit "
      OnRowDeleting=" gridCart_RowDel eting" OnRowEditing="g ridCart_RowEdit ing" OnRowUpdating=" gridCart_RowUpd ating">
      <Columns>
      <asp:BoundFie ld DataField="Prod uctName" HeaderText="Pro duct" ReadOnly="True" />
      <asp:BoundFie ld DataField="Quan tity" HeaderText="Qua ntity" DataFormatStrin g="{0:n}" >
      <ItemStyle HorizontalAlign ="Right" />
      </asp:BoundField>
      <asp:BoundFie ld DataField="Unit Price" DataFormatStrin g="{0:c2}" HeaderText="Uni t Price" ReadOnly="True" >
      <ItemStyle HorizontalAlign ="Right" />
      </asp:BoundField>
      <asp:BoundFie ld DataField="Pric e" DataFormatStrin g="{0:C2}" HeaderText="Pri ce" ReadOnly="True" >
      <ItemStyle HorizontalAlign ="Right" />
      </asp:BoundField>
      <asp:CommandFie ld ShowEditButton= "True" />
      <asp:CommandFie ld ShowDeleteButto n="True" />
      </Columns>
      </asp:GridView>

      From the aspx.cs file in Page_Load:

      if( !Page.IsPostBac k )
      {
      gridCart.DataSo urce = SiteInfo.Cart;
      gridCart.DataBi nd();
      }

      - Mark

      Comment

      • Steven Cheng[MSFT]

        #4
        Re: GridView: Empty OldValues, NewValues

        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

        OldValuesParame terFormatString ="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 <ChairmanMAO@ne wsgroups.nospam >
        | Newsgroups: microsoft.publi c.dotnet.framew ork.aspnet
        | Subject: Re: GridView: Empty OldValues, NewValues
        | Date: Fri, 20 Jan 2006 07:16:09 -0800
        | Organization: Olbert & McHugh, LLC
        | Reply-To: mark@arcabama.c om
        | Message-ID: <pgv1t11on94cv3 lpa2a2lmoeskbu6 ivqnk@4ax.com>
        | References: <tuivs1ppk2aud1 ailae8p6cmfcsbm ct7uk@4ax.com>
        <BKH9MNZHGHA.12 40@TK2MSFTNGXA0 2.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+kJ pAmoBOGULDT2IaO t8mm0XAdS3/H8Wolx8XkjG2Ejq yINMBt07V7vW05b 7
        BZLOjiS!+eHmPdz x7M/uknFZJOhFDbJ5W5 f40+9WyC2ZrYcAV cbqV8rb5BTKgyj7 24PJ7ARmnbYG
        EQ==
        | X-Complaints-To: abuse@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.p hx.gbl!TK2MSFTN GP08.phx.gbl!ne wsfeed00.sul.t-online.de!t-onli
        ne.de!news.glor b.com!postnews. google.com!news 3.google.com!bo rder1.nntp.dca. g
        iganews.com!nnt p.giganews.com! local01.nntp.dc a.giganews.com! news.giganews.c o
        m.POSTED!not-for-mail
        | Xref: TK2MSFTNGXA02.p hx.gbl
        microsoft.publi c.dotnet.framew ork.aspnet:3724 06
        | X-Tomcat-NG: microsoft.publi c.dotnet.framew ork.aspnet
        |
        | Steven,
        |
        | From the aspx file:
        |
        | <asp:GridView ID="gridCart" runat="server" AutoGenerateCol umns="False"
        CellPadding="2" CellSpacing="2" AllowPaging="Tr ue"
        | EmptyDataText=" the cart is empty"
        OnPageIndexChan ging="gridCart_ PageIndexChangi ng"
        OnRowCancelingE dit="gridCart_R owCancelingEdit "
        | OnRowDeleting=" gridCart_RowDel eting" OnRowEditing="g ridCart_RowEdit ing"
        OnRowUpdating=" gridCart_RowUpd ating">
        | <Columns>
        | <asp:BoundFie ld DataField="Prod uctName" HeaderText="Pro duct"
        ReadOnly="True" />
        | <asp:BoundFie ld DataField="Quan tity" HeaderText="Qua ntity"
        DataFormatStrin g="{0:n}" >
        | <ItemStyle HorizontalAlign ="Right" />
        | </asp:BoundField>
        | <asp:BoundFie ld DataField="Unit Price" DataFormatStrin g="{0:c2}"
        HeaderText="Uni t Price" ReadOnly="True" >
        | <ItemStyle HorizontalAlign ="Right" />
        | </asp:BoundField>
        | <asp:BoundFie ld DataField="Pric e" DataFormatStrin g="{0:C2}"
        HeaderText="Pri ce" ReadOnly="True" >
        | <ItemStyle HorizontalAlign ="Right" />
        | </asp:BoundField>
        | <asp:CommandFie ld ShowEditButton= "True" />
        | <asp:CommandFie ld ShowDeleteButto n="True" />
        | </Columns>
        | </asp:GridView>
        |
        | From the aspx.cs file in Page_Load:
        |
        | if( !Page.IsPostBac k )
        | {
        | gridCart.DataSo urce = SiteInfo.Cart;
        | gridCart.DataBi nd();
        | }
        |
        | - Mark
        |

        Comment

        • Mark Olbert

          #5
          Re: GridView: Empty OldValues, NewValues

          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

          Comment

          • Steven Cheng[MSFT]

            #6
            Re: GridView: Empty OldValues, NewValues

            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 <ChairmanMAO@ne wsgroups.nospam >
            | Newsgroups: microsoft.publi c.dotnet.framew ork.aspnet
            | Subject: Re: GridView: Empty OldValues, NewValues
            | Date: Mon, 23 Jan 2006 09:00:13 -0800
            | Organization: Olbert & McHugh, LLC
            | Reply-To: mark@arcabama.c om
            | Message-ID: <ho2at1tkfo7gvt 46ogalj5t877hf1 idvk2@4ax.com>
            | References: <tuivs1ppk2aud1 ailae8p6cmfcsbm ct7uk@4ax.com>
            <BKH9MNZHGHA.12 40@TK2MSFTNGXA0 2.phx.gbl>
            <pgv1t11on94cv3 lpa2a2lmoeskbu6 ivqnk@4ax.com>
            <RxrOTgCIGHA.12 36@TK2MSFTNGXA0 2.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-U9nK6TomeE9bhjk WeXcn08zAR1rLXu fi10YwNgyd0i3SW gCu++zPjD1xg6GV JGAbK7Dnh2WO
            bVwtOgT!haAJ9Zn cP8Ei3q+L2+nGKN 1K6B5U57An5wPDT lBfTRhgocD5IBPr xek8OkQ6ARdran4 7
            nw==
            | X-Complaints-To: abuse@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.p hx.gbl!TK2MSFTN GP08.phx.gbl!ne wsfeed00.sul.t-online.de!t-onli
            ne.de!border2.n ntp.dca.giganew s.com!border1.n ntp.dca.giganew s.com!nntp.giga n
            ews.com!local01 .nntp.dca.gigan ews.com!news.gi ganews.com.POST ED!not-for-mail
            | Xref: TK2MSFTNGXA02.p hx.gbl
            microsoft.publi c.dotnet.framew ork.aspnet:3729 22
            | X-Tomcat-NG: microsoft.publi c.dotnet.framew ork.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
            |

            Comment

            Working...