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

Confirming Delete for a asp:ButtonColumn in asp:datagrid..

RSB
Hi Everyone,
i am using a ASP: DataGrid control in the page and for each row i have a
Delete Button Column. Every thing works fine.
But now i want to add a Java script confirmation check for the user that
Delete has been selected and are they sure to continue.

I have already used this Attributes.Add (
cmdDelete.Attributes.Add("onClick", "return confirmDelete();")

)

command for a Single delete button on the page but don't understand how to
add some thing same for the dataGrid Button.

Please help.

Thanks
RSB
Nov 18 '05 #1
6 4645
For the template column...

<asp:TemplateColumn>
<ItemTemplate>
<span onclick="unlockChild(this, 'delete');">
<asp:LinkButton runat="server" Text="X" CommandName="Delete"
CausesValidation="false"></asp:LinkButton>
</span>
</ItemTemplate>
</asp:TemplateColumn>

and the corresponding JavaScript function...

<script language="javascript">
<!--
function unlockChild(parentObj, action){
var allowClick = confirm('Are you sure you want to ' + action + ' this
item?');
window.event.returnValue = allowClick;
return allowClick;
}
//-->

-John Oakes

"RSB" <rs*****@hotmail.com> wrote in message
news:GA****************@news.cpqcorp.net...
Hi Everyone,
i am using a ASP: DataGrid control in the page and for each row i have a
Delete Button Column. Every thing works fine.
But now i want to add a Java script confirmation check for the user that
Delete has been selected and are they sure to continue.

I have already used this Attributes.Add (
cmdDelete.Attributes.Add("onClick", "return confirmDelete();")

)

command for a Single delete button on the page but don't understand how to
add some thing same for the dataGrid Button.

Please help.

Thanks
RSB

Nov 18 '05 #2
Hi RSB,

you need to do it in DataGrid1_ItemCreated
get the (button) control instance by using the findcontrol method and then
attach the script using control.Attributes.Add method.

Button myButton = (Button) this.findControl("btnDelete")
myButton.Attributes.Add("onclick",return confirmDelete();");
Regards
Ashish M Bhonkiya

"RSB" <rs*****@hotmail.com> wrote in message
news:GA****************@news.cpqcorp.net...
Hi Everyone,
i am using a ASP: DataGrid control in the page and for each row i have a
Delete Button Column. Every thing works fine.
But now i want to add a Java script confirmation check for the user that
Delete has been selected and are they sure to continue.

I have already used this Attributes.Add (
cmdDelete.Attributes.Add("onClick", "return confirmDelete();")

)

command for a Single delete button on the page but don't understand how to
add some thing same for the dataGrid Button.

Please help.

Thanks
RSB

Nov 18 '05 #3
Asish is right but I found in certain instances the ItemCreated is not
reliable. I used ItemDataBound of the datagrid to accomplish this.

this.dgGrid1.ItemDataBound += new
System.Web.UI.WebControls.DataGridItemEventHandler (this.dgGrid1_ItemDataBoun
d); //put this line of code in the InitializeComponent method or in the
PageLoad event

private void dgGrid1_ItemDataBound(object sender, DataGridItemEventArgs e)
{
try
{

if(e.Item.ItemType==ListItemType.Item
||e.Item.ItemType==ListItemType.AlternatingItem)
{

LinkButton lbtn=(LinkButton)e.Item.FindControl("btnDelete");

if(lbtn!=null)
{

lbtn.Attributes.Add("onclick","return confirm('Are you sure you want to
delete?');");

}

}
}
catch(Exception ex)
{
throw ex;
}

}

Prodip

"RSB" <rs*****@hotmail.com> wrote in message
news:GA****************@news.cpqcorp.net...
Hi Everyone,
i am using a ASP: DataGrid control in the page and for each row i have a
Delete Button Column. Every thing works fine.
But now i want to add a Java script confirmation check for the user that
Delete has been selected and are they sure to continue.

I have already used this Attributes.Add (
cmdDelete.Attributes.Add("onClick", "return confirmDelete();")

)

command for a Single delete button on the page but don't understand how to
add some thing same for the dataGrid Button.

Please help.

Thanks
RSB

Nov 18 '05 #4
RSB
Thanks every one that helped..
it is working :o))
Nov 18 '05 #5
Please add the deligate method inside the InitializeComponent method. This
method executes before page load.
Prodip
"Lane" <an*******@discussions.microsoft.com> wrote in message
news:7C**********************************@microsof t.com...
I tried this solution Prodip sugeested and got a error regarding the ItemDataBound in the page load area???

Nov 18 '05 #6
"Lane" <an*******@discussions.microsoft.com> wrote in message
news:7C**********************************@microsof t.com...
I tried this solution Prodip sugeested and got a error regarding the

ItemDataBound in the page load area???


This is a sample in the itemcreated event for the grid
......
ListItemType elemType = e.Item.ItemType;
if (elemType == ListItemType.Item || elemType
=ListItemType.AlternatingItem)
{
//add code to get button instance

button.Attributes.Add ("onclick",
"return confirm ('Are you sure?');");

}
....
Karim

Nov 18 '05 #7

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

Similar topics

1
by: MrMike | last post by:
Hi. I have an ASP datagrid column which is small in size, but sometimes contains a large amount of text. User's often complain that they cannot read the entire text of this column because the...
1
by: Tim Smith | last post by:
In my .cs code I populate set the DataSource appropriately and I can get my DataGrid to appear, though sorting throws an error 'dgDataGrid1__ctl1__ctl0' of type 'DataGridLinkButton' must be placed...
1
by: Paresh | last post by:
Hi I need to Print asp:datagrid with formatting, which will avoid my writing of crystal reports and can directly print with click of a button. I do not just want to print the current page, I...
1
by: Michael M | last post by:
Hi I am trying to add mouseover property to asp:datagrid in the asp .net page My pag So the output in HTML for a row should look like <tr style="onmouseover=this.bgcolor=#ff0000;...
4
by: Mark Travis | last post by:
Hi all, I have written a simple Web Application that displays a query result onto a page using the ASP DataGrid. To Digress ======= Development information about the page is as follows 1....
2
by: John | last post by:
Hi, First off .. I am very new to ASP.NET (.NET in general), so this may be a very basic question. I have traditionally used a set of style classes for html tables and the first row in those...
15
by: John Blair | last post by:
Hi, Code attached but the line that gives me an error is MyDataGrid.Columns(2).Visible = False It actually gives me an error for any value instead of 2 even when 9 bound columns of data exist....
2
by: =?Utf-8?B?RXNlbWk=?= | last post by:
I have a datatable that contains a number of web addresses as type nvarchar (eg 'www.msdn.com'). I want to use these as hyperlinks in a datagrid column. Whats the best way to do this? How can I...
2
by: getziiiiiiiiiii | last post by:
Hi There. . I need some help in paging (which is not working) in ASP:DATAGRID My Data source id is a function which returns DataTable to this datagrid. Do i need a code behind to get the next...
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: 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
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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...
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...

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.