?
Solved

asp.net c# gridview deletecommand with warning

Posted on 2009-04-13
3
Medium Priority
?
732 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
3 Comments
 
LVL 1

Accepted Solution

by:
Shyam_Saraf earned 1500 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

New benefit for Premium Members - Upgrade now!

Ready to get started with anonymous questions today? It's easy! Learn more.

Question has a verified solution.

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

A quick way to get a menu to work on our website, is using the Menu control and assign it to a web.sitemap using SiteMapDataSource. Example of web.sitemap file: (CODE) Sample code to add to the page menu: (CODE) Running the application, we wi…
The article shows the basic steps of integrating an HTML theme template into an ASP.NET MVC project
If you’ve ever visited a web page and noticed a cool font that you really liked the look of, but couldn’t figure out which font it was so that you could use it for your own work, then this video is for you! In this Micro Tutorial, you'll learn yo…
In this video you will find out how to export Office 365 mailboxes using the built in eDiscovery tool. Bear in mind that although this method might be useful in some cases, using PST files as Office 365 backup is troublesome in a long run (more on t…

752 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