Groups > Asp .Net > Getting started with ASP.NET > Re: Adding Confirmation message for the Delete button in the grid




Adding Confirmation message for the Delete button in the
grid

Adding Confirmation message for the Delete button in the grid
Thu, 3 Apr 2008 17:33:35 +0000
Hi everybody,

I'm working on a manage site users page (based on Membership and Profile
classes). I found this great article
http://peterkellner.net/2006/03/13/adding-personalization-via-profiles-to-the-ob
jectdatasource-in-aspnet-20/ which helped me to create an object source for my
GridView.

However, as a newbie I'm having problems.

1. I want to show only users from non Admin group and only for the particular
site (based on Profile.SiteID). In the original code of the page I had code to
get only those users. My question is how should I change the auto-generated
class to be able to restrict users based on criteria and role?

 

2. Much simpler problem - but somehow I'm stack again. In my grid I have Delete
Button. For this button I want to add a confirmation message.

Using this code:

protected void grdDeleteUsers_RowDataBound(object sender, GridViewRowEventArgs
e)
    {
        if (e.Row.DataItem != null)
        {
            ImageButton btnDelete = (ImageButton) e.Row.Cells[0].Controls[0];  

           e.Row.ToolTip = "Delete " +  e.Row.DataItem.ToString()  ;

           btnDelete.Attributes["onclick"] =
               "return confirm('Do you want to delete " +
               e.Row.DataItem.ToString() + "?' );";

           //btnDelete.CommandArgument = "RemUser";        
         }
     }

 

Gives a dialog, but doesn't delete. Removing OnClick attribute deletes record
without any extra code.


Do you know why I can not add  confirmation dialog with this code?

Thanks a lot in advance.
Post Reply
Re: Adding Confirmation message for the Delete button in the grid
Thu, 3 Apr 2008 22:12:35 +0000
<html>
<head>
<script type="text/javascript">
<!--
function confirmation() {
var answer = confirm("Leave tizag.com?")
if (answer){
alert("Bye bye!")
window.location = "http://www.google.com/";
}
else{
alert("Thanks for sticking around!")
}
}
//-->
</script>
</head>
<body>
<form>
<input type="button" onclick="confirmation()"
value="Leave Tizag.com">
</form>
</body>
</html>


 

 from  http://www.tizag.com/javascriptT/javascriptconfirm.php
Post Reply
Re: Adding Confirmation message for the Delete button in the grid
Thu, 3 Apr 2008 22:29:59 +0000
I don't understand how does it solve my problem. I'm saying, that using 

 

<asp:View ID="vwDeleteUsers" runat="server">          
    
                    <div class="backGroundArea"
style="text-align: center; padding: 4,4,4,4;">                    
                        <table style="text-align: center; width:
80%">
                            <tr>
                                <td style="vertical-align: middle;
width: 166px; height: 157px;" >
                                    <asp:GridView
ID="grdDeleteUsers" runat="server"
AutoGenerateColumns="False" 
                                         CellPadding="4"
                                        DataKeyNames="UserName"
AllowSorting="True"
                                        ForeColor="#333333"
GridLines="None" ToolTip="Select user to Delete" 
                                       
OnRowDataBound="grdDeleteUsers_RowDataBound" 
                                        Width="379px"                 
                       
                                        DataSourceID="odsDeleteGrid"
AllowPaging="True" PageSize="5">
                                        <RowStyle
BackColor="#F7F6F3" ForeColor="#333333" />
                                        <EditRowStyle
BackColor="#999999" />
                                        <SelectedRowStyle
Backcolor="LightCyan" ForeColor="DarkBlue"
Font-Bold="True"/>  
                                        <PagerStyle
BackColor="#284775" ForeColor="White"
HorizontalAlign="Center" />
                                        <HeaderStyle
BackColor="#5D7B9D" Font-Bold="True"
ForeColor="White" />
                                        <AlternatingRowStyle
BackColor="White" ForeColor="#284775" />
                                        <Columns>
                                            <asp:CommandField
ButtonType="Image"
DeleteImageUrl="~/images/id_card_delete.gif"
                                               
ShowDeleteButton="True" />
                                            <asp:BoundField
DataField="UserName" HeaderText="User Name"
ReadOnly="True" SortExpression="UserName" />
                                            <asp:BoundField
DataField="FirstName" HeaderText="First Name"
SortExpression="FirstName" />
                                            <asp:BoundField
DataField="MiddleName" HeaderText="Middle Name"
SortExpression="MiddleName" />
                                            <asp:BoundField
DataField="LastName" HeaderText="Last Name"
SortExpression="LastName" />
                                            <asp:BoundField
DataField="Email" HeaderText="E-Mail"
SortExpression="Email" />
                                            <asp:BoundField
DataField="TelephoneNum" HeaderText="Telephone"
SortExpression="TelephoneNum" />
                                            <asp:BoundField
DataField="LastActivityDate" HeaderText="Last Activity Date"
SortExpression="LastActivityDate" />
                                            <asp:BoundField
DataField="IsOnline" HeaderText="Is Online"
SortExpression="IsOnline" />
                                        </Columns>
                                    </asp:GridView>                       

                 

and using the code above to add a confirmation dialog disables the built-in
Delete functionality.

Removing confirmation activates Delete functionality back.

I can switch to the ItemTemplate, but in this case I would have to program
Delete functionality myself and I'm not sure how to do it.

Thanks in advance.
Post Reply
about | contact