Wrox Programmer Forums
Go Back   Wrox Programmer Forums > .NET > Other .NET > General .NET
|
General .NET For general discussion of MICROSOFT .NET topics that don't fall within any of the other .NET forum subcategories or .NET language forums.  If your question is specific to a language (C# or Visual Basic) or type of application (Windows Forms or ASP.Net) try an applicable forum category. ** PLEASE BE SPECIFIC WITH YOUR QUESTION ** When posting here, provide details regarding the Microsoft .NET language you are using and/or what type of application (Windows/Web Forms, etc) you are working in, if applicable to the question. This will help others answer the question without having to ask.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the General .NET section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old December 6th, 2004, 02:36 AM
Friend of Wrox
 
Join Date: Sep 2003
Posts: 363
Thanks: 0
Thanked 1 Time in 1 Post
Default Confirm delete row in datagrid

Hello,

  How can i confirm before delete a row from datagrid?
This is my code...
<asp:datagrid id="dgbrand" Runat="server" Font-Size="12px" Font-Name="arial" BorderColor="SteelBlue" OnEditCommand="editMode" OnUpdateCommand="doUpdate" OnCancelCommand="cancelEdit" DataKeyField="brand_code"
AutoGenerateColumns="False" Width="350px" Font-Names="arial" OnDeleteCommand="doDelete">
<AlternatingItemStyle BackColor="#CCCCCC"></AlternatingItemStyle>
<HeaderStyle Font-Bold="True" BackColor="Salmon"></HeaderStyle>
<Columns>
<asp:EditCommandColumn ButtonType="LinkButton" UpdateText="Update" CancelText="CAN" EditText="Edit"></asp:EditCommandColumn>
<asp:BoundColumn DataField="brand_code" ReadOnly="True" HeaderText="Brand Code">
    <ItemStyle HorizontalAlign="Center"></ItemStyle>
    </asp:BoundColumn>
    <asp:BoundColumn DataField="brand_name" HeaderText="Description"></asp:BoundColumn>
    <asp:TemplateColumn>
    <ItemTemplate>
    <asp:LinkButton ID="cmddel" Runat="server" Font-Underline="True" ForeColor="#0000ff" CommandName="Delete">Del</asp:LinkButton>
    </ItemTemplate>
    </asp:TemplateColumn>
</Columns>
</asp:datagrid>



    Sub doDelete(ByVal s As Object, ByVal e As DataGridCommandEventArgs)
        Dim bcode As String, strqry As String
        Dim cmd As OleDbCommand, mydelbtn As LinkButton
        bcode = dgbrand.DataKeys.Item(e.Item.ItemIndex)
        mydelbtn = e.Item.FindControl("cmddel")

        bcode = dgbrand.DataKeys.Item(e.Item.ItemIndex)
        strqry = "delete from brands where brand_code='" & bcode & "'"

        cmd = New OleDbCommand(strqry, conn)
        cmd.CommandType = CommandType.Text
        Try
            If conn.State = ConnectionState.Closed Then
                conn.Open()
            End If
            cmd.ExecuteNonQuery()
            getNewBrandCode()
            dobinding()
            txtDesc.Value = ""
        Catch ex As Exception
            errmsg.Text = ex.ToString()
        End Try
        conn.Close()
    End Sub




 
Old December 6th, 2004, 07:59 AM
Friend of Wrox
 
Join Date: Jun 2004
Posts: 449
Thanks: 0
Thanked 1 Time in 1 Post
Send a message via MSN to r_ganesh76
Default

In the ItemDataBound Event of the Grid, Find the LinkButton
     LinkButton cmdDel = e.Item.FindControl("cmdDel");

add client side code to this LinkButton
     cmdDel.Attributes.Add("onclick", "return confirm('Are You Sure You want to delete?')")

Regards
Ganesh
 
Old December 8th, 2004, 09:42 AM
Authorized User
 
Join Date: Mar 2004
Posts: 47
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Example:

 Private Sub dgbrand_ItemDataBound(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.DataGridItemEventArgs) Handles dgbrand.ItemDataBound
        Dim link_cmddel As LinkButton
        If e.Item.ItemType = ListItemType.AlternatingItem Or e.Item.ItemType = ListItemType.Item Then
            link_cmddel = e.Item.FindControl("cmddel")
link_cmddel.Attributes.Add("onclick", "return confirm('Are You Sure You want to delete?')")
        End If
    End Sub

 
Old December 8th, 2004, 09:27 PM
Friend of Wrox
 
Join Date: Sep 2003
Posts: 363
Thanks: 0
Thanked 1 Time in 1 Post
Default

Hello,

  Tx 4 the replies. I got it.


----------
Rajani






Similar Threads
Thread Thread Starter Forum Replies Last Post
To delete and Accept a row in DataGrid vijay_83 ASP.NET 1.0 and 1.1 Basics 3 September 19th, 2006 02:15 PM
Accept and Delete a row in DataGrid vijay_83 ASP.NET 1.0 and 1.1 Basics 2 September 19th, 2006 12:15 PM
a problem of adding a confirm window to delete but raybristol ASP.NET 1.0 and 1.1 Basics 1 December 12th, 2005 05:01 PM
how delete row in datagrid which check checkbox ashish2001mca Forum and Wrox.com Feedback 1 September 18th, 2005 03:43 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.