CSDN博客

img xuandhu

删除过程中使用dt.Rows.Find(ItemsGrid.DataKeys(e.Item.ItemIndex))

发表于2004/10/21 13:06:00  1150人阅读

分类: ASP.NET三组件

 Sub Delete_Command(sender As Object, e As DataGridCommandEventArgs)

         ' Retrieve the data table from session state.
         Dim dt As DataTable = CType(Session("Source"), DataTable)

         ' Retrieve the data row to delete from the data table.
         ' Use the DataKeys property of the DataGrid control to get
         ' the primary key value of the selected row.
         ' Search the Rows collection of the data table for this value.
         Dim row As DataRow
         row = dt.Rows.Find(ItemsGrid.DataKeys(e.Item.ItemIndex))

         ' Delete the item selected in the DataGrid from the data source.
         If Not row is Nothing Then
        
            dt.Rows.Remove(row)
        
         End If

         ' Save the data source.
         Session("Source") = dt

         ' Create a DataView and bind it to the DataGrid control.
         Dim dv As DataView = New DataView(dt)
         ItemsGrid.DataSource = dv
         ItemsGrid.DataBind()

      End Sub

0 0

相关博文

我的热门文章

img
取 消
img