364,085 Members | 5378 Browsing Online
Community for Developers & IT Professionals
Bytes IT Community

Delete Items in a DataGrid Web Server Control

tomcarr1@gmail.com
P: n/a
tomcarr1@gmail.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 #1
Share this Question
Share on Google+
2 Replies


Norman Yuan
P: n/a
Norman Yuan
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.

<tomcarr1@gmail.com> wrote in message
news:1149706885.725034.226830@i39g2000cwa.googlegr oups.com...[color=blue]
> 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?
>[/color]


Jun 7 '06 #2

tomcarr1@gmail.com
P: n/a
tomcarr1@gmail.com
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:[color=blue]
> 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.
>
> <tomcarr1@gmail.com> wrote in message
> news:1149706885.725034.226830@i39g2000cwa.googlegr oups.com...[color=green]
> > 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?
> >[/color][/color]

Jun 7 '06 #3

Post your reply

Help answer this question



Didn't find the answer to your .NET Framework question?

You can also browse similar questions: .NET Framework