473,804 Members | 3,557 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

DataGrid Delete Problem

Hi all,

I hope someone can help with this relatively simple problem.
I am building a timesheet application using ASP.NET C# with Visual
Studio 2003.As it is only a protoype application, my database has been
made in MSDE.

I have a DataGrid, and have inserted a delete link button into it
through Property Builder. My Delete method works fine, however I would
like to insert a JScript popup to confirm, as otherwise users can just
delete from the database. With my normal buttons, such as a 'submit'
button on a form, I can just use the following code:

btnSubmit.Attri butes.Add("oncl ick","javascrip t:if(confirm('C reate new
Department - are you sure?')== false) return false;");

However with the DataGrid, the Delete link is created through the
DataGrid, and I do not know how to assign JavaScript to it. I'm sure
someone else must've had this problem before, as no-one wants users to
be able to just delete records so freely! :-)

I have already tried following this guide, but can't get it to work..

http://www.dotnetjunkies.com/HowTo/1...EB07C94A8.dcik

Any suggestions on how anyone has achieved this would be much
appreciated!

Al

Apr 13 '06 #1
1 1456
You can add that attribute by implementing the ItemCreated Event of the
datagrid.
Here is some sample VB.NET code. I am pretty sure you can easily rewrite
this to C#

Public Sub yourdatagrid_It emCreated(ByVal sender As Object, e as
DataGridEventAr gs) Handles yourdatagrid.It emCreated

If (e.Item.ItemTyp e = ListItemType.It em Or e.ItemType =
ListItemType.Al ternatingItem)
Dim btn As Button = Nothing
btn = CType(e.Item.Ce lls(cell_index) .Controls(0), Button)

btn.Attributes. Add("onclick"," javascript:if(c onfirm('Create new
Department - are you sure?')== false) return false;")
End If

If (e.Item.ItemTyp e = ListItemType.Ed itItem)
Dim btn As Button = Nothing
btn = CType(e.Item.Ce lls(cell_index) .Controls(0), Button)

btn.Attributes. Add("onclick"," javascript:if(c onfirm('Create new
Department - are you sure?')== false) return false;")
End If

End Sub

You have to do this both for the Item/AlternatingItem and EditItem because
when you are in edit mode the cell index will be different.

Hope this helps.

"thebison" <al************ @btinternet.com > wrote in message
news:11******** *************@z 34g2000cwc.goog legroups.com...
Hi all,

I hope someone can help with this relatively simple problem.
I am building a timesheet application using ASP.NET C# with Visual
Studio 2003.As it is only a protoype application, my database has been
made in MSDE.

I have a DataGrid, and have inserted a delete link button into it
through Property Builder. My Delete method works fine, however I would
like to insert a JScript popup to confirm, as otherwise users can just
delete from the database. With my normal buttons, such as a 'submit'
button on a form, I can just use the following code:

btnSubmit.Attri butes.Add("oncl ick","javascrip t:if(confirm('C reate new
Department - are you sure?')== false) return false;");

However with the DataGrid, the Delete link is created through the
DataGrid, and I do not know how to assign JavaScript to it. I'm sure
someone else must've had this problem before, as no-one wants users to
be able to just delete records so freely! :-)

I have already tried following this guide, but can't get it to work..

http://www.dotnetjunkies.com/HowTo/1...EB07C94A8.dcik

Any suggestions on how anyone has achieved this would be much
appreciated!

Al

Apr 14 '06 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

9
1646
by: Pam Ammond | last post by:
After clicking btnDeleteSize_Click in frmSize, I move to frmSizeDelete, allow deleting a Size using a datagrid, and then return to frmSize and want to update the datagrid in frmSize to reflect the deletion. I can't figure out how to get the datagrid in frmSize updated, although the datagrid in frmSizeDelete shows the deletion properly. In frmSizeDelete the size is properly deleted when the user clicks the row in the datagrid and presses...
3
5047
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, then put this control on a form. I use DataAdaptor to fill the data table and update database.
0
317
by: Curtis Hatter | last post by:
I apologize if this has been answered, but on the .NET 247 site I saw a thread titled "Datagrid's ItemCommand Event", and had similar troubles with the Datagrid not properly firing the delete event if using a push button. I could not find the thread here, so I'm posting my finding's here in hopes that it will help others that are having the same problem. The problem: In a DataGrid the "Delete" command does not fire properly from a...
0
473
by: Steve | last post by:
I have a datagrid that is created at run time DataGrid dgG = new DataGrid(); BoundColumn bcB; dgG.CellPadding = 5; dgG.CellSpacing = 0; dgG.GridLines = GridLines.Both; dgG.CssClass = "SectionTableLines"; dgG.DataKeyField = "PlanWorkOrderID";
4
2132
by: Rod | last post by:
I posted a message to this group yesterday asking how to pass parameters to a web form that is the source of an IFrame on a parent web form. I've gotten my answer, and it works. Thanks! Now I have a different problem. The web form that is in the IFrame has a DataGrid in it. I have a button column in it which I use to trigger the deletion of the row in the database, and I want it to also reflect that deletion in the data grid. The...
4
1831
by: Steve | last post by:
I am fairly new to VB.NET, and I am rewriting an application I wrote a while back, also in VB.NET. I aplied some new things I learned. Anyway, here is my problem....... I have a custom DataGrid with a buttonRow that does a delete function for me. Microsoft support helped me back then to get this done. Here is part of the code that creates the dataGrid: Dim ButtonColStyle As DataGridButtonColumn
0
1513
by: laurent | last post by:
Environment: VS NET 2003 Fr Framework: 1.1 OS: WinXP SP2 Fr Hello I have a problem to add with pop-up and to delete in a datagrid(ButtonColumn delete) on WebForms. code button HTML which opens pop-up: <INPUT class="buttonForm" onclick="MM_openBrWindow('../pages/recherche_ar.aspx?a=2','AR','width=700,height=500,scrollbars=yes,resizable=yes')"
5
6706
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 missing here, but after 2 days I am ready to explode ! Please help. To create the Delete button I selected the grid in design view, clicked the "Columns" property and added the Delete button in the
4
2139
by: Jeff User | last post by:
Hi I tryed to solve this problem over in the framework.asp group, but still am having trouble. Hope someone here can help. using .net 1.1, VS 2003 and C# I have an asp.DataGrid control with a Delete button on the end of each row. I am unable to gain access to the event when the button is clicked. I don't fully understand how the click gets connected to the C# code,
10
2975
by: amiga500 | last post by:
Hello, I have one basic simple question. When I have multiple records in the datagrid as follows: Code Product 1 Product 2 Product 3 11111 A B C 22222 D E F 33333 G H I 44444 J K L
0
9706
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9584
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10583
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
10323
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
1
7622
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5525
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5654
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
3822
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2995
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.