Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
1329
New rows added on the Client Side, but some rows cell values are lost on a PostBack
posted

I am able to add new rows to my WHDG using JavaScript.

var childGrid = _getChildGridView();
childGrid.get_rows().add(newRow);

In my example, if a Parent had 3 Child Rows (1 row was present, the other 2 were added on the client), I am able to see all of my rows on a PostBack including my 2 new rows. However, only one row has data while iterating the rows. 

        Protected Sub getContainerGrid(ByVal gridView As ContainerGrid)
            ' Iterate through rows
            For i As Integer = 0 To gridView.Rows.Count - 1
                If gridView.Rows(i).Items.Count = 28 Then
                    If gridView.Rows(i).Items(12).Value = "Y" Then
                        gridView.Rows(i).CssClass = "someCssClassName"
                    End If
                End If

                ' Recursively call the method for each row
                If gridView.Rows(i).HasRowIslands Then
                    getContainerGrid(gridView.Rows(i).RowIslands(0))
                End If
            Next
        End Sub

Here is the result...

gridView.Rows(0).Items(3).Value = "100.00" (last row added on client)

gridView.Rows(1).Items(3).Value = Nothing (second row added on client)

gridView.Rows(2).Items(3).Value = Nothing (present row on load)

Any help would be appreciated!

  • 1329
    Verified Answer
    posted

    I have solved this issue. I added e.Band.DataKeyFields = "primaryKeyID" to the grid's _InitializeBand() event handler and it now works like a charm. It also solved a duplicating key error on the client side when you click into a cell of any new rows that were added via the client.