Solved

asp.net c# gridview deletecommand with warning

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

What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

Lots of people ask this question on how to extend the “MembershipProvider” to make use of custom authentication like using existing database or make use of some other way of authentication. Many blogs show you how to extend the membership provider c…
Problem Hi all,    While many today have fast Internet connection, there are many still who do not, or are connecting through devices with a slower connect, so light web pages and fast load times are still popular.    If your ASP.NET page …
Illustrator's Shape Builder tool will let you combine shapes visually and interactively. This video shows the Mac version, but the tool works the same way in Windows. To follow along with this video, you can draw your own shapes or download the file…
This video explains how to create simple products associated to Magento configurable product and offers fast way of their generation with Store Manager for Magento tool.

747 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

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now