473,397 Members | 2,056 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,397 software developers and data experts.

Delete Items in a DataGrid Web Server Control

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
2 1752
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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: Stephen | last post by:
I have got an event below to remove items from an arraylist and then to rebind the arraylist to the datagrid subsequently deleting the appropriate row. My problem is that my code makes sense and I...
0
by: Bob Rosen | last post by:
The description given in "Customizing Items Dynamically in the DataList or DataGrid Web Server Control" (http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dv_vbCode/...
3
by: Ryan Liu | last post by:
Hi there, I got a NullReferenceException when delete last row in a datagrid. I had hard time to solve since it does not occur in my own code. I put a datagrid in my inherited user control,...
3
by: vcornjamb | last post by:
Hello, I am developing a web form that contains some buttons and a data grid which has as its last column link buttons that will delete the data associated with that row. Everything works fine,...
6
by: JenHu | last post by:
Hi experts, I want to add a delete button in my datagrid, and before it deletes from database, I want to have a confirm dialog box for this deletion. I am entry level to the vb.net, and don't...
6
by: I am Sam | last post by:
I keep getting this error and I don't know why: The path is too long after being fully qualified. Make sure path is less than 260 characters. Description: An unhandled exception occurred...
4
by: DrData | last post by:
I'm working on an ASP.Net application written in C#. On one page, there are several datagrid controls used to display, edit and delete detail records relating to the master record also displayed on...
3
by: NateDawg | last post by:
I'm reposting this. I'm kinda in a bind untill i get this figured out, so if anyone has some input it would sure help me out. Ok, I’ve noticed a few gridview problems floating around the forum....
5
by: Jeff User | last post by:
Hello ..NET 1.1, VS 2003, C# & asp.net I have tried to follow msdn instructions and samples but I can not get an event to fire for this button on the datagrid. There has to be something obvious...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.