Solved

asp.net c# gridview deletecommand with warning

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

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…
IntroductionWhile developing web applications, a single page might contain many regions and each region might contain many number of controls with the capability to perform  postback. Many times you might need to perform some action on an ASP.NET po…
This is a video that shows how the OnPage alerts system integrates into ConnectWise, how a trigger is set, how a page is sent via the trigger, and how the SENT, DELIVERED, READ & REPLIED receipts get entered into the internal tab of the ConnectWise …
Delivering innovative fully-managed cloud services for mission-critical applications requires expertise in multiple areas plus vision and commitment. Meet a few of the people behind the quality services of Concerto.

929 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

14 Experts available now in Live!

Get 1:1 Help Now