Link to home
Start Free TrialLog in
Avatar of pgilfeather
pgilfeather

asked on

Problems with code while performing updatecommand from datagrid with strongly typed dataset


I have the following datagrid

VideoDetailID   Edit Column   VideoTitle   VideoDuration   VideoURL   GlobalAccessID
       1                 Edit            MyTitle          2.46              C:/......           25
       2                 Edit            MyTitle2        3.56              C:/......           32

I have used a strongly typed dataset and am trying to implement the update command.

The following is my code for the updatecommand

Private Sub dgTypedDataGrid_UpdateCommand(ByVal source As Object, ByVal e As System.Web.UI.WebControls.DataGridCommandEventArgs) Handles dgTypedDataGrid.UpdateCommand
        BindToGrid()

        'Dim the values you are working with
        Dim VideoTitle As String
        Dim VideoDuration As Decimal
        Dim VideoUrl As String
        Dim GlobalAccessID As String

        Dim dt As DataTable
        Dim dr As DataRow

        Dim txt As TextBox

        'Retrieve the changed data
        txt = CType(e.Item.Controls(2).Controls(0), TextBox)
        VideoTitle = CType(txt.Text, String)

        txt = CType(e.Item.Controls(3).Controls(0), TextBox)
        VideoDuration = CType(txt.Text, Decimal)

        txt = CType(e.Item.Controls(4).Controls(0), TextBox)
        VideoUrl = CType(txt.Text, String)

        txt = CType(e.Item.Controls(5).Controls(0), TextBox)
        GlobalAccessID = CType(txt.Text, Integer)

        'Retrieve stored data
        Dim VideoCache As DataSet = CType(Cache.Get("VideoCache"), DataSet)
        dt = VideoCache.Tables("tblVideoDetail")
        dr = dt.Rows.Find(CStr(e.Item.Cells(2).Text))

        If Not (dr Is Nothing) Then
            With dr
                .Item("VideoTitle") = VideoTitle
                .Item("VideoDuration") = VideoTitle
                .Item("VideoUrl") = VideoTitle
                .Item("GlobalAccessID") = VideoTitle
            End With
        End If

        daVideoDetails.Update(dt)

        'Restore the grid to read only
        dgTypedDataGrid.EditItemIndex = -1
        BindToGrid()

    End Sub


The above code keeps stopping at  dr = dt.Rows.Find(CStr(e.Item.Cells(2).Text)) and saying 'Input string not in correct format'

To be honest I dont know what  "dr = dt.Rows.Find(CStr(e.Item.Cells(2).Text))"  is supposed to be doing since all my columns in the datagrid are editable and cells(2) seems to me to be hard coded.

I hope all this makes sense.

Cheers

Paul G








ASKER CERTIFIED SOLUTION
Avatar of raterus
raterus
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Avatar of Bob Learned
Bob Learned
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial