Solved

asp.net c# gridview deletecommand with warning

Posted on 2009-04-13
3
726 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

Efficient way to get backups off site to Azure

This user guide provides instructions on how to deploy and configure both a StoneFly Scale Out NAS Enterprise Cloud Drive virtual machine and Veeam Cloud Connect in the Microsoft Azure Cloud.

Question has a verified solution.

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

Just a quick little trick I learned recently.  Now that I'm using jQuery with abandon in my asp.net applications, I have grown tired of the following syntax:      (CODE) I suppose it just offends my sense of decency to put inline VBScript on a…
The article shows the basic steps of integrating an HTML theme template into an ASP.NET MVC project
This tutorial gives a high-level tour of the interface of Marketo (a marketing automation tool to help businesses track and engage prospective customers and drive them to purchase). You will see the main areas including Marketing Activities, Design …
This video shows how to quickly and easily add an email signature for all users on Exchange 2016. The resulting signature is applied on a server level by Exchange Online. The email signature template has been downloaded from: www.mail-signatures…

803 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