473,385 Members | 1,748 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,385 software developers and data experts.

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.Attributes.Add("onclick","javascript:if( confirm('Create 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 1428
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_ItemCreated(ByVal sender As Object, e as
DataGridEventArgs) Handles yourdatagrid.ItemCreated

If (e.Item.ItemType = ListItemType.Item Or e.ItemType =
ListItemType.AlternatingItem)
Dim btn As Button = Nothing
btn = CType(e.Item.Cells(cell_index).Controls(0), Button)

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

If (e.Item.ItemType = ListItemType.EditItem)
Dim btn As Button = Nothing
btn = CType(e.Item.Cells(cell_index).Controls(0), Button)

btn.Attributes.Add("onclick","javascript:if(confir m('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*********************@z34g2000cwc.googlegro ups.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.Attributes.Add("onclick","javascript:if( confirm('Create 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
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...
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,...
0
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...
0
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 =...
4
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...
4
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...
0
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...
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...
4
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...
10
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...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

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.