2011-04-05 43 views
0

我有一個GridView顯示結果,並從中刪除使用自動創建的刪除鏈接的結果。我的代碼後面刪除行和關聯的信息。是:沒有結果從GridView.SelectedRow.Cells(x).Text返回?

Private Sub GridView1_RowDeleting(sender As Object, e As System.Web.UI.WebControls.GridViewDeleteEventArgs) Handles GridView1.RowDeleting 
    ' The deletion of the individual row is automatically handled by the GridView. 
    Dim dbDelete As New pbu_housingEntities 
    ' Remove individual from the bed. 
    Dim remove_bed = From p In dbDelete.Beds _ 
        Where p.occupant = GridView1.SelectedRow.Cells(3).Text _ 
        Where p.room = GridView1.SelectedRow.Cells(6).Text _ 
        Where p.building = GridView1.SelectedRow.Cells(5).Text _ 
        Order By p.id Descending _ 
        Select p 

    remove_bed.First.occupant = "" 
    dbDelete.SaveChanges() 

    ' Increase number of open spaces in room. 
    Dim update_occupancy = From p In dbDelete.Rooms _ 
          Where p.room1 = GridView1.SelectedRow.Cells(6).Text 
          Where p.building = GridView1.SelectedRow.Cells(5).Text _ 
          Select p 

    update_occupancy.First.current_occupancy = update_occupancy.First.current_occupancy - 1 
    dbDelete.SaveChanges() 


End Sub 

看來,它不能夠抓住正在被刪除的行,所以它總是給我錯誤「不設置到對象的實例對象引用」。

回答

1

使用GridView1.Rows(e.RowIndex).Cells(.......