Solved

asp.net c# gridview deletecommand with warning

Posted on 2009-04-13
3
727 Views
Last Modified: 2012-06-27
Hi,

How do I insert a warning in my deletecommand to prevent delete mistakes?
DeleteCommand="DELETE FROM [bokningsDB] WHERE [b_id] = @b_id">
 
and in my gridview it looks like this:
<asp:GridView ID="GridView1" runat="server" AutoGenerateDeleteButton="true"............

Open in new window

0
Comment
Question by:mattegol
  • 2
3 Comments
 
LVL 1

Accepted Solution

by:
Shyam_Saraf earned 500 total points
ID: 24130597
Try this--
put this logic in code behind rowdatabound event of grid

 protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
 {
        if (e.Row.RowType == DataControlRowType.DataRow)
        {        
                LinkButton lnkDelete = (LinkButton)e.Row.FindControl("lnkbtnDelete");// id of delete button
                lnkDelete.Attributes.Add("onclick", "return fnConfirmDelete();");
            }
}

----------
Put this javascript in aspx page in script section
function fnConfirmDelete()
{
 return confirm("Confirm Delete?");
}

0
 

Author Comment

by:mattegol
ID: 24131920
The javascript doesn't popup, where do I declare the linkbutton?
This is how it looks now:
<asp:SqlDataSource ID="SqlDataSource1" runat="server"
            ConnectionString="<%$ ConnectionStrings:KharazmiConnectionString %>"            
            UpdateCommand="UPDATE bokningsDB SET epostID = @epostID, telefonID = @telefonID, bokningsnr = @bokningsnr, datum = @datum,
            tidpunkt = @tidpunkt, platser = @platser, height = @platser * 20, kommentar = @kommentar  
            WHERE b_id = @b_id"
            DeleteCommand="DELETE FROM [bokningsDB] WHERE [b_id] = @b_id">

            <DeleteParameters>
                <asp:Parameter Name="b_id" Type="Int32" />
            </DeleteParameters>

           
            <UpdateParameters>
                <asp:Parameter Type="int32" Name="b_id" />
                <asp:Parameter Type="string"  Name="epostID" />
                <asp:Parameter Type="string"  Name="telefonID" />
                <asp:Parameter Type="string"  Name="bokningsnr" />
                <asp:Parameter Type="string"  Name="datum" />
                <asp:Parameter Type="string"  Name="tidpunkt" />
                <asp:Parameter Type="int32"  Name="platser" />
                <asp:Parameter Type="string"  Name="height" />
                <asp:Parameter Type="string"  Name="kommentar" />
           </UpdateParameters>
        </asp:SqlDataSource>
       
         <asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False"
            DataKeyNames="b_id" Width="800px" DataSourceID="SqlDataSource1" CellPadding="4"
            ForeColor="#333333" CssClass="textbox" GridLines="None"
            AllowPaging="True">

            <Columns>
           
            <asp:CommandField HeaderStyle-Width="100" ShowEditButton="True" CausesValidation="False" />
           
            <asp:BoundField DataField="b_id" HeaderText="ID" InsertVisible="False"  ReadOnly="True" SortExpression="b_id" />                  
            <asp:BoundField DataField="epostID" HeaderText="epostID" SortExpression="epostID" />
            <asp:BoundField DataField="telefonID" HeaderText="telefonID" SortExpression="telefonID" />
            <asp:BoundField DataField="bokningsnr" HeaderText="bokningsnr" SortExpression="bokningsnr" />
            <asp:BoundField DataField="datum" HeaderText="datum" SortExpression="datum" />
            <asp:BoundField DataField="tidpunkt" HeaderText="tidpunkt" SortExpression="tidpunkt" />
            <asp:BoundField DataField="platser" HeaderText="platser" SortExpression="platser" />
            <asp:BoundField DataField="kommentar" HeaderText="kommentar" SortExpression="kommentar" />                  
            <asp:TemplateField HeaderText="Delete">
            <ItemTemplate>
            <asp:LinkButton ID="lnkbtnDelete" runat="server" CommandName="Delete" Text="Delete">
           
            </asp:LinkButton>
            </ItemTemplate>
            </asp:TemplateField>
           
            </Columns>
     

            <RowStyle CssClass="storlek" BackColor="#F7F6F3" ForeColor="#333333" />
            <FooterStyle CssClass="storlek" BackColor="#5D7B9D" Font-Bold="True" ForeColor="White" />
            <PagerStyle BackColor="#284775" ForeColor="White" HorizontalAlign="Center" />
            <SelectedRowStyle BackColor="#E2DED6" Font-Bold="True" ForeColor="#333333" />
            <HeaderStyle BackColor="#5D7B9D" Font-Bold="True" ForeColor="White" />
            <AlternatingRowStyle BackColor="White" ForeColor="#284775" />
                <EditRowStyle BackColor="#999999" />

            </asp:GridView>
0
 

Author Closing Comment

by:mattegol
ID: 31569508
ty
0

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

This article discusses the ASP.NET AJAX ModalPopupExtender control. In this article we will show how to use the ModalPopupExtender control, how to display/show/call the ASP.NET AJAX ModalPopupExtender control from javascript, how to show/display/cal…
ASP.Net to Oracle Connectivity Recently I had to develop an ASP.NET application connecting to an Oracle database.As I am doing it first time ,I had to solve several problems. This article will help to such developers  to develop an ASP.NET client…
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…
In an interesting question (https://www.experts-exchange.com/questions/29008360/) here at Experts Exchange, a member asked how to split a single image into multiple images. The primary usage for this is to place many photographs on a flatbed scanner…

827 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question