473,748 Members | 10,737 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Confirming Delete for a asp:ButtonColum n 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.Attri butes.Add("onCl ick", "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 4667
For the template column...

<asp:TemplateCo lumn>
<ItemTemplate >
<span onclick="unlock Child(this, 'delete');">
<asp:LinkButt on runat="server" Text="X" CommandName="De lete"
CausesValidatio n="false"></asp:LinkButton>
</span>
</ItemTemplate>
</asp:TemplateCol umn>

and the corresponding JavaScript function...

<script language="javas cript">
<!--
function unlockChild(par entObj, action){
var allowClick = confirm('Are you sure you want to ' + action + ' this
item?');
window.event.re turnValue = allowClick;
return allowClick;
}
//-->

-John Oakes

"RSB" <rs*****@hotmai l.com> wrote in message
news:GA******** ********@news.c pqcorp.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.Attri butes.Add("onCl ick", "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_ItemC reated
get the (button) control instance by using the findcontrol method and then
attach the script using control.Attribu tes.Add method.

Button myButton = (Button) this.findContro l("btnDelete" )
myButton.Attrib utes.Add("oncli ck",return confirmDelete() ;");
Regards
Ashish M Bhonkiya

"RSB" <rs*****@hotmai l.com> wrote in message
news:GA******** ********@news.c pqcorp.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.Attri butes.Add("onCl ick", "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.It emDataBound += new
System.Web.UI.W ebControls.Data GridItemEventHa ndler(this.dgGr id1_ItemDataBou n
d); //put this line of code in the InitializeCompo nent method or in the
PageLoad event

private void dgGrid1_ItemDat aBound(object sender, DataGridItemEve ntArgs e)
{
try
{

if(e.Item.ItemT ype==ListItemTy pe.Item
||e.Item.ItemTy pe==ListItemTyp e.AlternatingIt em)
{

LinkButton lbtn=(LinkButto n)e.Item.FindCo ntrol("btnDelet e");

if(lbtn!=null)
{

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

}

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

}

Prodip

"RSB" <rs*****@hotmai l.com> wrote in message
news:GA******** ********@news.c pqcorp.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.Attri butes.Add("onCl ick", "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 InitializeCompo nent method. This
method executes before page load.
Prodip
"Lane" <an*******@disc ussions.microso ft.com> wrote in message
news:7C******** *************** ***********@mic rosoft.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*******@disc ussions.microso ft.com> wrote in message
news:7C******** *************** ***********@mic rosoft.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.It em || elemType
=ListItemType.A lternatingItem)
{
//add code to get button instance

button.Attribut es.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
1436
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 column simply isn't large enough. Is it possible to create a "mouse-over" effect so that when a user places their mouse over this column a ballon or something appears over their mouse displaying the entire column text? Thanks, MrMike
1
1353
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 inside a form tag But ignoring that, with my asp:DataGrid how can I have a column of values each with a link e.g. <a href="Details.aspx?id=" + MY_NBR>MY_NBR</a>
1
1499
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 want to print all the pages in that datagrid, as I have used paging in the datagrid (there is an underlying datatable which holds the data).
1
1829
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; onmouseout=this.bgcolor=#00ff00;" Binding is done in C# page
4
2353
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. The database used is SqlServer 2000. 2. A Stored Procedure is dragged onto the page from the Server Explorer
2
1288
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 tables. However, I am trying to use a data bound DataGrid and can't seem to figure out how to set the class for the first row. Any insight would be appreiciated.
15
3764
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. How do i hide a column? Thanks. MyConnection = New SqlConnection("server=(local);database=pubs;Trusted_Connection=yes") MyCommand = New SqlDataAdapter("select * from Authors",
2
1278
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 set the NavigateURL property for each row of a HyperLinkField column dynamically? Is this even the best way to do it? Thanks
2
6560
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 page working? thanks for help. this is how my data grid look like:
0
8991
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
8830
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
9541
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...
0
9370
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
8242
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
4874
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3312
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
2
2782
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2215
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.