GridView.SelectedRow.Cells(x).Text 没有返回结果?

发布于 2024-10-30 20:46:02 字数 1295 浏览 0 评论 0原文

我有一个 GridView,它显示结果,并使用自动创建的删除链接从中删除结果。我的代码隐藏在删除行和相关信息的后面。是:

  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

它似乎无法获取正在删除的行,因此它总是给我一个“对象引用未设置到对象实例”错误。

I have a GridView which is showing results and from which I am deleting a result using the auto-created delete link. My code behind to remove the row and associated info. is:

  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

It seems that it is not able to grab the row that is being deleted, so it is always giving me a "Object reference not set to an instance of an object" error.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

苹果你个爱泡泡 2024-11-06 20:46:02

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

Use GridView1.Rows(e.RowIndex).Cells(.......

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文