Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

delete row in datagrid/dataset ALMOST working...

Status
Not open for further replies.

gagz

Programmer
Nov 21, 2002
333
US
This is *almost* working... for some reason, when I press the delete link (in a ButtonColumn, commandname="Delete"), I get:
Code:
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code. 

Exception Details: System.IndexOutOfRangeException: There is no row at position 2.

Source Error: 


Line 231:        Dim i As Integer
Line 232:        For i = 0 To ds.Tables("Details").Rows.Count() - 1
Line 233: Dim dscol1 = ds.Tables("Details").Rows(i).Item("ID")
Code:
Line 234:
Line 235:            If dscol1 = SelectedID Then

but if i hit reload and repost, it removes the correct record... what the heck is going on??? i've rebooted, cleared cache, all that jazz... by the way, there were 3 rows when i got that, I printed it to a textbox to make sure it had all the rows...

here is the delete code.
Code:
    Sub MeetingDetails_DeleteCommand(ByVal source As System.Object, ByVal e As System.Web.UI.WebControls.DataGridCommandEventArgs)
        Dim dr As DataRow

        Dim SelectedID As String = MeetingDetails.DataKeys(e.Item.ItemIndex)

        Dim ds As New DataSet()
        ds = Session("MeetingDetailsDS")

        Dim dTable As New DataTable()
        dTable = ds.Tables("Details")

        txtFoodReqs.Text = SelectedID

        Session("MeetingDetailsDS") = ds
        Dim i As Integer
        For i = 0 To ds.Tables("Details").Rows.Count() - 1
            Dim dscol1 = ds.Tables("Details").Rows(i).Item("ID")

            If dscol1 = SelectedID Then
                ds.Tables("Details").Rows(i).Delete()
            End If

        Next
        ds.Tables("Details").AcceptChanges()

        Dim agendaDV As DataView = New DataView(ds.Tables("Details"), "", "Date,Start,End ASC", DataViewRowState.CurrentRows)

        Session("MeetingDetailsDS") = ds

        MeetingDetails.DataSource = agendaDV
        MeetingDetails.DataBind()

    End Sub

any help is greatly appreciated...
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top