473,761 Members | 2,285 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

JS Confirm dialog from datagrid template column

Hi,

I am trying to implement a JS confirm dialog when a user is deleting
something off my Datagrid.
The problem is that I don't have a Delete button in which case I could write
the following function:

btnDelete.Attri butes.Add("onCl ick", "if(confirm('Ar e you sure you want to
delete this order?')){}else {return false}");

I have a Delete Command which is evaluated in my ItemCommand like so:

private void dgOrder_ItemCom mand(object source,
System.Web.UI.W ebControls.Data GridCommandEven tArgs e)
{ if ((e.Item.ItemTy pe == ListItemType.Al ternatingItem) ||{...
if (e.CommandName == "Delete")
{
//delete the order//
}
}

Now in my html page, the Delete column is a Template Column and not a button
Column. How can I implement an onClick event for my template column, when
there is no button defined in my aspx.cs page.
My template column is:

<asp:TemplateCo lumn>
<ItemTemplate >
<asp:ImageButto n id="Imagebutton 1" runat="server" NAME="Imagebutt on1"
CausesValidatio n="false" CommandName="De lete"
alt="Delete" ImageUrl="Image s/deleteord.GIF"> </asp:ImageButton >
</ItemTemplate>
</asp:TemplateCol umn>

Thanks a lot
Pat
Nov 18 '05 #1
2 2101
It's very easy.

Since you have Imagebutton1 in TemplateColumn, you have to add JS to onclick
(just like you wrote).
You can do this during DataGrids ItemDataBound event, like this:
//Find delete button
ImageButton Imagebutton1 = (ImageButton )e.Item.FindCon trol("Imagebutt on1");

//We don't want to serach for this button in header or footer
if ((e.Item.ItemTy pe == ListItemType.It em) || (e.Item.ItemTyp e ==
ListItemType.Al ternatingItem))

{

//Add on click event
Imagebutton1 .Attributes["onClick"] =
"javascript:you r_JS_delete_com mand();";

}

You might add id attibute to IMageButton too.

Sebastian
Nov 18 '05 #2
Thanks Sebastian. Works well.
I also tried this approach without looking for the control:

e.Item.Cells[17].Attributes.Add ("onClick","if( confirm('Are you sure you want
to delete this order?')){}else {return false}");

works the same.

Thx.

Pat

I was trying e.item
"Sebastian" <po*****@mail.c om> wrote in message
news:%2******** ********@TK2MSF TNGP09.phx.gbl. ..
It's very easy.

Since you have Imagebutton1 in TemplateColumn, you have to add JS to onclick (just like you wrote).
You can do this during DataGrids ItemDataBound event, like this:
//Find delete button
ImageButton Imagebutton1 = (ImageButton )e.Item.FindCon trol("Imagebutt on1");
//We don't want to serach for this button in header or footer
if ((e.Item.ItemTy pe == ListItemType.It em) || (e.Item.ItemTyp e ==
ListItemType.Al ternatingItem))

{

//Add on click event
Imagebutton1 .Attributes["onClick"] =
"javascript:you r_JS_delete_com mand();";

}

You might add id attibute to IMageButton too.

Sebastian

Nov 18 '05 #3

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

Similar topics

2
2166
by: Jeremy | last post by:
I have a datagrid that users interact with to add/edit/delete, but before the .aspx submits for the delete action I want to pop up a JavaScript confirm box. If the user clicks OK on that box I want the page to be submited and to delete the item(s) from the grid, if the user clicks CANCEL I don't want the page to do a postback. So far I have everything working except the JavaScript confirm box (in other words the delete just happens
4
1748
by: ShadowsOfTheBeast | last post by:
hi oliver thanks for your help i kinda figured that out minutes afterwards...but what i am actually trying to do is this: i have a listbox control that gets its data from another listbox (hence gets a subset by selecting from the first list box) and i have a datagrid which has a template column and a bound column, i want to bind the bound column to this second listbox and then its template column implements a dropdownlist for every bound...
4
5978
by: Richard Roche | last post by:
Is it possible to use a drop combo instead of a text box when using the EditCommand in the Datagrid? Many table columns are bound to 'lookup' tables, user's don't care about the foreign keys, they want the text value. Any advice, samples or places to read are appreciated. Thanks.
2
2630
by: damonf | last post by:
I'm currently trying to add an ASP hyperlink to a template column in a datagrid. The normal hyperlink column doesn't give me the ability to add attributes to the item. In my grid there are four columns. Three are databound to a dataset and one is a template column. I need to be able to access each item in the template column (getting access to the hyperlink) then adding an attribute to call some client side code. Does anyone know...
4
1798
by: Stephan Bour | last post by:
Hi, I have a datagrid databound to a SQL query. I'd like to allow editing of some columns but not all. Is there a way to turn off the conversion of the datagrid cells to textboxes for some columns when the Edit button is pressed? Thank you, Stephan.
1
1495
by: RN | last post by:
Hi. I used this article to add a template column to a datagrid that is entirely created with code: http://msdn.microsoft.com/library/default.asp?url=/library/en-us/vbcon/html/vbtskcreatingtemplatesprogrammaticallyindatagridcontrol.asp It works fine except for one thing. My template column needs a field in the recordset that binds to the datagrid. The template column is an HTML radio button where the value of the radio button needs...
1
1878
by: Ken Varn | last post by:
I have a problem where my DataGrid would not maintain the ViewState of my databound rows. I finally narrowed down the problem. If my first column is a template column, the view state for the DataGrid items is not maintained on postback for some reason. I basically re-created my DataGrid again just to make sure this was indeed the problem. The ViewState was fine until I added the template column at the beginning of the Columns list. ...
8
3895
by: Matt | last post by:
Guys I could really use some help with this. I think that it's probably a simple solution but I haven't been able to find anything. I have a datagrid on my form that I populate via code like this... Me.My_DataGrid.Rows.Add(Column1, Column2, Column3) Well now I have a datagrid that I want to populate with an image. So for example...
4
7502
by: mamun | last post by:
Hi All, I have the following situation and am looking for answer in C#. I have a datagrid and putting checkbox next to each record. In the header I have a Delete button. I want users to checkchekboxes and click the Delete button. That will show a confirmation dialog message with the items they choose to delete.
1
9909
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,...
0
9788
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
7342
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
6623
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5241
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
5384
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3889
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
3481
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2765
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.