Tracking DataGrid changes

Discussion in 'ASP .Net' started by Glenn Owens, Jul 2, 2003.

  1. Glenn Owens

    Glenn Owens Guest

    I have a DataGrid web control which I've dynamically populated with
    template columns to be used for bulk-editting. Generally, all of the
    columns are textbox and/or dropdownlist child controls.

    Currently everything is working. I can find the updated rows/columns
    by parsing the posted data collection against the DataGrid DataSource.
    However, when there is a large amount of DataGridItems (rows) the
    update processing can take a while.

    What I'd like to do is to be able to, as changes are made, mark the
    row as modified (in an invisible temaplate column which I'll add to
    the DataGrid). That would provide a faster way to find modified rows
    without the parsing.

    My question:
    Has anyone done this? What are some options? Because of viewstate size
    concerns I'd prefer to go with a client-side (JavaScript) solution.

    TIA
    Glenn
    Glenn Owens, Jul 2, 2003
    #1
    1. Advertising

  2. Hello Glenn,
    If you are using Dataset, this functionality is already implemented. What
    you can do is to use the method, DataSet.GetChanges.
    This method will get a copy of the Dataset containing all changes made to
    it since it was last loaded, or since AcceptChanges
    was called. The you will loop through every row and mark accordingly the
    rows in the DataGrid. Another method to show
    the modified information, is to have a new DataGrid of the updated
    information.

    For more information on GetChanges method refers to:
    http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpref/html/
    frlrfsystemdatadatasetclassgetchangestopic.asp

    Please let me know if you need more help on this.

    Thanks,
    Bassel Tabbara
    Microsoft, ASP.NET

    This posting is provided "AS IS", with no warranties, and confers no rights.



    --------------------
    | From: (Glenn Owens)
    | Newsgroups: microsoft.public.dotnet.framework.aspnet
    | Subject: Tracking DataGrid changes
    | Date: 2 Jul 2003 08:31:18 -0700
    | Organization: http://groups.google.com/
    | Lines: 20
    | Message-ID: <>
    | NNTP-Posting-Host: 165.170.128.66
    | Content-Type: text/plain; charset=ISO-8859-1
    | Content-Transfer-Encoding: 8bit
    | X-Trace: posting.google.com 1057159878 25886 127.0.0.1 (2 Jul 2003
    15:31:18 GMT)
    | X-Complaints-To:
    | NNTP-Posting-Date: 2 Jul 2003 15:31:18 GMT
    | Path:
    cpmsftngxa09.phx.gbl!TK2MSFTNGP08.phx.gbl!newsfeed00.sul.t-online.de!newsfee
    d01.sul.t-online.de!t-online.de!newspeer1-gui.server.ntli.net!ntli.net!sn-xi
    t-02!sn-xit-06!sn-xit-09!supernews.com!postnews1.google.com!not-for-mail
    | Xref: cpmsftngxa09.phx.gbl microsoft.public.dotnet.framework.aspnet:31751
    | X-Tomcat-NG: microsoft.public.dotnet.framework.aspnet
    |
    | I have a DataGrid web control which I've dynamically populated with
    | template columns to be used for bulk-editting. Generally, all of the
    | columns are textbox and/or dropdownlist child controls.
    |
    | Currently everything is working. I can find the updated rows/columns
    | by parsing the posted data collection against the DataGrid DataSource.
    | However, when there is a large amount of DataGridItems (rows) the
    | update processing can take a while.
    |
    | What I'd like to do is to be able to, as changes are made, mark the
    | row as modified (in an invisible temaplate column which I'll add to
    | the DataGrid). That would provide a faster way to find modified rows
    | without the parsing.
    |
    | My question:
    | Has anyone done this? What are some options? Because of viewstate size
    | concerns I'd prefer to go with a client-side (JavaScript) solution.
    |
    | TIA
    | Glenn
    |
    Bassel Tabbara [MSFT], Jul 2, 2003
    #2
    1. Advertising

  3. Glenn Owens

    Glenn Owens Guest

    Bassel thanks for the reply.

    The problem is not with the update. Once I can get the DataGrid changes
    reflected in the DataTable (I'm currently using a DataView as the
    DataGrid source) then updating the database is no issue. I'm using the
    DataTable.GetChanges to pull the modifed/inserted/deleted DataTable rows
    for update.

    Perhaps I wasn't clear enough...

    For the bulk-edit, the DataGrid template columns are defined as the
    ItemTemplate (not the EditTemplate) - this makes the DataGrid look like
    a "spreadsheet". The User will update 1 or more columns on 1 or more
    rows and will then click the Save button. At that point the Save
    processing needs to extract the DataGrid data changes and place them
    into the corresponding rows/columns of the Datatable (followed by an
    Update/commit to the database).

    Again, while this all works currently I'm looking for a quicker way to
    migrate the DataGrid changes to the DataTable. I was assuming that some
    client-side coding would be faster than parsing the post data collection
    against the DataGrid data source (DataTable) on the server-side.

    Bassel, if I'm missing soming fundamental (wouldn't be the first time)
    please help me understand.

    Thanks again!
    Glenn


    *** Sent via Developersdex http://www.developersdex.com ***
    Don't just participate in USENET...get rewarded for it!
    Glenn Owens, Jul 2, 2003
    #3
  4. Hello Glenn,
    I am not sure I totally understand the problem/scenario that you are
    running into. I am not sure
    what you are looking for exactly. If you are trying to get the changes on
    the client side, this is
    a totally different route and you might have something custom to build it.
    If on the server, are you still looking to get changes?
    Please can you illustrate with a sample code or be more specific?
    I appreciate your cooperation so I can better help you.

    Thanks,
    Bassel Tabbara
    Microsoft, ASP.NET

    This posting is provided "AS IS", with no warranties, and confers no rights.



    --------------------
    | From: Glenn Owens <>
    | References: <>
    | X-Newsreader: AspNNTP 1.50 (ActionJackson.com)
    | Subject: RE: Tracking DataGrid changes
    | Mime-Version: 1.0
    | Content-Type: multipart/mixed; boundary="----=_NextPart_000_44774108"
    | Message-ID: <#>
    | Newsgroups: microsoft.public.dotnet.framework.aspnet
    | Date: Wed, 02 Jul 2003 15:15:18 -0700
    | NNTP-Posting-Host: actionjackson133.dsl.frii.net 216.17.147.133
    | Lines: 1
    | Path: cpmsftngxa09.phx.gbl!TK2MSFTNGP08.phx.gbl!TK2MSFTNGP12.phx.gbl
    | Xref: cpmsftngxa09.phx.gbl microsoft.public.dotnet.framework.aspnet:31867
    | X-Tomcat-NG: microsoft.public.dotnet.framework.aspnet
    |
    |
    | Bassel thanks for the reply.
    |
    | The problem is not with the update. Once I can get the DataGrid changes
    | reflected in the DataTable (I'm currently using a DataView as the
    | DataGrid source) then updating the database is no issue. I'm using the
    | DataTable.GetChanges to pull the modifed/inserted/deleted DataTable rows
    | for update.
    |
    | Perhaps I wasn't clear enough...
    |
    | For the bulk-edit, the DataGrid template columns are defined as the
    | ItemTemplate (not the EditTemplate) - this makes the DataGrid look like
    | a "spreadsheet". The User will update 1 or more columns on 1 or more
    | rows and will then click the Save button. At that point the Save
    | processing needs to extract the DataGrid data changes and place them
    | into the corresponding rows/columns of the Datatable (followed by an
    | Update/commit to the database).
    |
    | Again, while this all works currently I'm looking for a quicker way to
    | migrate the DataGrid changes to the DataTable. I was assuming that some
    | client-side coding would be faster than parsing the post data collection
    | against the DataGrid data source (DataTable) on the server-side.
    |
    | Bassel, if I'm missing soming fundamental (wouldn't be the first time)
    | please help me understand.
    |
    | Thanks again!
    | Glenn
    |
    |
    | *** Sent via Developersdex http://www.developersdex.com ***
    | Don't just participate in USENET...get rewarded for it!
    |
    |
    Bassel Tabbara [MSFT], Jul 7, 2003
    #4
  5. Glenn Owens

    Glenn Owens Guest

    Yes, I'm looking for an alternative to the server-side code that I
    currently have working. The code works (albeit not very fast) to
    perform multi-column, multi-row updates within an edittable DataGrid.
    My hope is that someone might suggest a JavaScript solution, with
    example, (as I'm still coming up-to-speed with JavaScript) that will
    identify modified rows in the DataGrid.

    My thoughts around the client-side sollution:

    o As the User modifies a column, in the DataGrid, a hidden column
    (added by my server control) would be marked (i.e. a DataGrid
    rowstatus column)

    o When the User clicks the Save button for the DataGrid the code can
    quickly find each modified DataGrid row and migrate the changes to the
    DataTable for update.

    The following is the server-side method that I'm currently using.

    '===============================================================================
    ' Author: Glenn W. Owens
    ' Date: 7/7/2003
    '
    ' Description:
    ' This method uses the PostBack data for the Fluid control to
    populate,
    ' and update, any/all DDO data records which have been modified.
    '
    ' Parameters:
    ' postCollection - when the user clicks the "Save" control button
    the page
    ' collects the user-entered data into the Postback
    data
    ' collection. This data collection becomes the
    data source
    ' to update the existing DDO data record.
    '
    '===============================================================================

    Private Sub ExecuteDataGridUpdate(ByVal postCollection As
    NameValueCollection)
    Me.SetDefaultSelect(ListSelectKey)

    Ddo.Retrieve(ListWhere) 'Re-retrieve the DDO data to update

    Dim dc As DataColumn
    Dim idx As Integer
    Dim key As String
    Dim newval As String
    Dim oldval As String
    Dim ctlOffset As Integer
    Dim target As String = ":FluidListControl:_ctl"

    '----------------------------------------------------------------------------
    ' Determine the control offset to use when referencing items from
    the
    ' postCollection. The postCollection entries that we're
    interested in look
    ' like:
    '
    ' UniqueId:FluidListControl:_ctl[offset]:_....
    '
    ' We need the offset number from the first postCollection entry
    that
    ' matches the pattern. The offset will be used to sychronize the
    post data
    ' collection with the DataGrid items (rows).
    '----------------------------------------------------------------------------

    For idx = 0 To postCollection.Count - 1
    key = postCollection.Keys(idx)

    If key.IndexOf(target) > 0 Then
    Dim start As Integer = key.IndexOf(":_ctl")
    Dim finish As Integer = key.LastIndexOf(":_")

    If (start > 0) And (finish > start) Then
    start += 5

    ctlOffset = CInt(key.Substring(start, finish - start))

    Exit For
    End If
    End If
    Next

    '----------------------------------------------------------------------------
    ' Parse through the DataGrid items (rows). Each modified table
    cell
    ' DataGrid value will be subsequently set to the DDO DataTable.
    When we're
    ' done parsing the DataGrid the updated DataTable rows will be
    processed
    ' via the DDO Update method.
    '----------------------------------------------------------------------------

    For idx = 0 To Ddo.DataViewCount - 1
    Dim items As New SetItemCollection()
    Dim modified As Boolean = False

    '-------------------------------------------------------------------------
    ' For each modified data item, for this Fluid control, add the
    item to
    ' the Ddo SetItemCollection
    '-------------------------------------------------------------------------

    For Each dc In Ddo.ColumnCollection
    If (Not dc.ReadOnly) And _
    (Ddo.DdoColumnProperties.Visible(dc.ColumnName)) And _
    (Ddo.DdoColumnProperties.EditEnabled(dc.ColumnName)) Then
    key = UniqueID + _
    ":FluidListControl:_ctl" + (idx + ctlOffset).ToString()
    + ":_"

    If Ddo.IsDropDownColumn(dc.ColumnName) Then
    Dim ctlidx As Integer = 0
    Dim ddldc As DataColumn

    '----------------------------------------------------------------
    ' Due to the way in which DropDownList controls (in
    Table
    ' cells) are identified we need to find the
    dropdownlist
    ' columns and count the ordinal position of the
    control
    ' relative to preceeding dropdownlist, and invisible,
    ' controls. This ordinal index will be appended to
    the static
    ' key (which references the postCollection data).
    '----------------------------------------------------------------

    For Each ddldc In Ddo.ColumnCollection
    If (Ddo.IsDropDownColumn(ddldc.ColumnName)) Or _
    (Not
    Ddo.DdoColumnProperties.Visible(ddldc.ColumnName)) Then
    ctlidx += 1

    If ddldc.ColumnName = dc.ColumnName Then
    Exit For
    End If
    End If
    Next

    key += "ctl" + ctlidx.ToString()
    Else
    key += dc.ColumnName
    End If

    Try
    '----------------------------------------------------------------
    ' If the current value in the post data collection
    differs
    ' from the data retrieved by the DDO then the
    row/data item
    ' has been modified. The Data item will be added to
    the update
    ' collection.
    '----------------------------------------------------------------

    newval = postCollection(key).ToString()
    oldval = Ddo.GetDataRow(idx)(dc.ColumnName).ToString()

    If newval <> oldval Then
    modified = True

    items.Add(newval, dc.ColumnName)
    End If

    Catch ex As System.Exception

    End Try
    End If
    Next

    If modified Then
    '----------------------------------------------------------------------
    ' Data item(s) were changed for this DataGrid row. Add the
    changes
    ' to the DDO DataTable.
    '----------------------------------------------------------------------

    Ddo.SetItems(items, idx)

    modified = False
    End If
    Next

    '----------------------------------------------------------------------------
    ' Populate the new data record and add it to the DDO DataTable
    '----------------------------------------------------------------------------

    Try
    Dim parms() As String = {Ddo.Update().ToString()}

    Message = GetLocalizedText("FluidRecordUpdated", parms, parms(0)
    + _
    " Record(s) Updated.")

    Catch ex As System.Exception
    Dim parms() As String = {ex.Message}

    ErrorMessage = GetLocalizedText("FluidUpdateError", parms, _
    "Error Updating Record: " + ex.Message)
    End Try
    End Sub

    ("Bassel Tabbara [MSFT]") wrote in message news:<R$>...
    > Hello Glenn,
    > I am not sure I totally understand the problem/scenario that you are
    > running into. I am not sure
    > what you are looking for exactly. If you are trying to get the changes on
    > the client side, this is
    > a totally different route and you might have something custom to build it.
    > If on the server, are you still looking to get changes?
    > Please can you illustrate with a sample code or be more specific?
    > I appreciate your cooperation so I can better help you.
    >
    > Thanks,
    > Bassel Tabbara
    > Microsoft, ASP.NET
    >
    > This posting is provided "AS IS", with no warranties, and confers no rights.
    >
    >
    >
    > --------------------
    > | From: Glenn Owens <>
    > | References: <>
    > | X-Newsreader: AspNNTP 1.50 (ActionJackson.com)
    > | Subject: RE: Tracking DataGrid changes
    > | Mime-Version: 1.0
    > | Content-Type: multipart/mixed; boundary="----=_NextPart_000_44774108"
    > | Message-ID: <#>
    > | Newsgroups: microsoft.public.dotnet.framework.aspnet
    > | Date: Wed, 02 Jul 2003 15:15:18 -0700
    > | NNTP-Posting-Host: actionjackson133.dsl.frii.net 216.17.147.133
    > | Lines: 1
    > | Path: cpmsftngxa09.phx.gbl!TK2MSFTNGP08.phx.gbl!TK2MSFTNGP12.phx.gbl
    > | Xref: cpmsftngxa09.phx.gbl microsoft.public.dotnet.framework.aspnet:31867
    > | X-Tomcat-NG: microsoft.public.dotnet.framework.aspnet
    > |
    > |
    > | Bassel thanks for the reply.
    > |
    > | The problem is not with the update. Once I can get the DataGrid changes
    > | reflected in the DataTable (I'm currently using a DataView as the
    > | DataGrid source) then updating the database is no issue. I'm using the
    > | DataTable.GetChanges to pull the modifed/inserted/deleted DataTable rows
    > | for update.
    > |
    > | Perhaps I wasn't clear enough...
    > |
    > | For the bulk-edit, the DataGrid template columns are defined as the
    > | ItemTemplate (not the EditTemplate) - this makes the DataGrid look like
    > | a "spreadsheet". The User will update 1 or more columns on 1 or more
    > | rows and will then click the Save button. At that point the Save
    > | processing needs to extract the DataGrid data changes and place them
    > | into the corresponding rows/columns of the Datatable (followed by an
    > | Update/commit to the database).
    > |
    > | Again, while this all works currently I'm looking for a quicker way to
    > | migrate the DataGrid changes to the DataTable. I was assuming that some
    > | client-side coding would be faster than parsing the post data collection
    > | against the DataGrid data source (DataTable) on the server-side.
    > |
    > | Bassel, if I'm missing soming fundamental (wouldn't be the first time)
    > | please help me understand.
    > |
    > | Thanks again!
    > | Glenn
    > |
    > |
    > | *** Sent via Developersdex http://www.developersdex.com ***
    > | Don't just participate in USENET...get rewarded for it!
    > |
    > |
    Glenn Owens, Jul 8, 2003
    #5
    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. fred tate via .NET 247

    Tracking Data Changes over time

    fred tate via .NET 247, May 1, 2004, in forum: ASP .Net
    Replies:
    1
    Views:
    358
    AlexS
    May 2, 2004
  2. =?Utf-8?B?YWppdA==?=

    tracking page controls changes

    =?Utf-8?B?YWppdA==?=, Feb 23, 2005, in forum: ASP .Net
    Replies:
    0
    Views:
    301
    =?Utf-8?B?YWppdA==?=
    Feb 23, 2005
  3. Sumukh
    Replies:
    4
    Views:
    491
    Ulf_N
    Mar 8, 2005
  4. funkazio

    tracking struts forms changes

    funkazio, Sep 21, 2005, in forum: Java
    Replies:
    0
    Views:
    368
    funkazio
    Sep 21, 2005
  5. jb
    Replies:
    1
    Views:
    303
    Andrew McDonagh
    Jun 3, 2006
Loading...

Share This Page