By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
429,251 Members | 2,760 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 429,251 IT Pros & Developers. It's quick & easy.

Delete Items in a DataGrid Web Server Control

P: n/a
In this walkthrough on "Allowing Users to Delete Items in a DataGrid
Web Server Control" at:

ms-help://MS.VSCC.2003/MS.MSDNQTR.2003FEB.1033/vbcon/html/vbtskallowinguserstodeleteitemsindatagridwebcontro l.htm

it leaves out some very important code. Here is what it gives you:

' Visual Basic
Private Sub DataGrid1_DeleteCommand(ByVal source As Object, _
ByVal e As System.Web.UI.WebControls.DataGridCommandEventArgs ) _
Handles DataGrid1.DeleteCommand
Dim index As Integer
index = e.Item.ItemIndex
' Add code to delete data from data source.
DataGrid1.DataBind()
End Sub

Where is says "Add code to delete data from data source" I have no idea
what to add. Can someone tell me what goes there, or point me to a
walkthough or example that goes into more detail?

Jun 7 '06 #1
Share this Question
Share on Google+
2 Replies


P: n/a
It all depends on what type of data is bound to the DataGrid, and how yo can
identify the actual data/record according to the ItemIndex of the DataGrid.

A simple case would be a DataTable is bound to this DataGrid and the
DataRow's ID column is bound to the first column of the DataGrid (and set
its Visible=False).

So, you could do this:

Dim id As String=e.Item.Cells(0).Text
Dim dr As DataRow=theDataTable.Select("IDColumn=" & id)(0)
dr.Delete

You would decide if oe when to update the deletion back to the database.

<to******@gmail.com> wrote in message
news:11**********************@i39g2000cwa.googlegr oups.com...
In this walkthrough on "Allowing Users to Delete Items in a DataGrid
Web Server Control" at:

ms-help://MS.VSCC.2003/MS.MSDNQTR.2003FEB.1033/vbcon/html/vbtskallowinguserstodeleteitemsindatagridwebcontro l.htm

it leaves out some very important code. Here is what it gives you:

' Visual Basic
Private Sub DataGrid1_DeleteCommand(ByVal source As Object, _
ByVal e As System.Web.UI.WebControls.DataGridCommandEventArgs ) _
Handles DataGrid1.DeleteCommand
Dim index As Integer
index = e.Item.ItemIndex
' Add code to delete data from data source.
DataGrid1.DataBind()
End Sub

Where is says "Add code to delete data from data source" I have no idea
what to add. Can someone tell me what goes there, or point me to a
walkthough or example that goes into more detail?

Jun 7 '06 #2

P: n/a
Thanks Norman. I got it to delete using this code:

Dim index As Integer
index = e.Item.ItemIndex
' Add code to delete data from data source.
DsTasks1.Tasks.Rows(index).Delete()
Me.OleDbDataAdapter1.Update(DsTasks1)
' Refreshes the grid
DataGrid1.DataBind()


Norman Yuan wrote:
It all depends on what type of data is bound to the DataGrid, and how yo can
identify the actual data/record according to the ItemIndex of the DataGrid.

A simple case would be a DataTable is bound to this DataGrid and the
DataRow's ID column is bound to the first column of the DataGrid (and set
its Visible=False).

So, you could do this:

Dim id As String=e.Item.Cells(0).Text
Dim dr As DataRow=theDataTable.Select("IDColumn=" & id)(0)
dr.Delete

You would decide if oe when to update the deletion back to the database.

<to******@gmail.com> wrote in message
news:11**********************@i39g2000cwa.googlegr oups.com...
In this walkthrough on "Allowing Users to Delete Items in a DataGrid
Web Server Control" at:

ms-help://MS.VSCC.2003/MS.MSDNQTR.2003FEB.1033/vbcon/html/vbtskallowinguserstodeleteitemsindatagridwebcontro l.htm

it leaves out some very important code. Here is what it gives you:

' Visual Basic
Private Sub DataGrid1_DeleteCommand(ByVal source As Object, _
ByVal e As System.Web.UI.WebControls.DataGridCommandEventArgs ) _
Handles DataGrid1.DeleteCommand
Dim index As Integer
index = e.Item.ItemIndex
' Add code to delete data from data source.
DataGrid1.DataBind()
End Sub

Where is says "Add code to delete data from data source" I have no idea
what to add. Can someone tell me what goes there, or point me to a
walkthough or example that goes into more detail?


Jun 7 '06 #3

This discussion thread is closed

Replies have been disabled for this discussion.