Click here to Skip to main content
16,015,755 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi,


I have some doubts in gridview. Plz help me.I Have a web application that contains gridview. Within the gridview there is "delete" button. How can i get the button click event code with in the gridview. Plz help me.

//Default.aspx
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Default.aspx.cs" Inherits="GRIDVIEW_DELETE_MULTIPLE_RECORDS_USING_CHECKBOX._Default" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" >
<head  runat="server">
    <title>Untitled Page</title>
    <script type="text/javascript">
    function confirmondelete(item)
    {
    if(confirm("would you like to delete selected item(s)?")==true)
    return true;
    else
    return false;
    }
    </script>
</head>
<body>
    <form id="form1"  runat="server">
        <asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" 
        onrowdatabound="GridView1_RowDataBound" onselectedindexchanged="GridView1_SelectedIndexChanged" 
            >
            <columns>
                <asp:TemplateField>
                <HeaderTemplate>
                    <asp:Button ID="ButtonDelete" runat="server" Text="Delete"/>
                </HeaderTemplate>
                    <itemtemplate>
                        <asp:CheckBox ID="CheckBox1" runat="server" />
                    </itemtemplate>
                
                <asp:BoundField DataField="EmpID" HeaderText="EmpID" ReadOnly="True" />
                <asp:BoundField DataField="EmpName" HeaderText="EmpName" />
                <asp:BoundField DataField="Address" HeaderText="Address" />
                <asp:BoundField DataField="Phone" HeaderText="Phone" />
                <asp:BoundField DataField="Salary" HeaderText="Salary" />
                <asp:BoundField DataField="Country" HeaderText="Country" />
            </columns>
        
    <div>
    </div>
    </form>
</body>
</html>
Posted
Updated 5-Apr-11 19:39pm
v2

1 solution

Using CommandName property of button and Gridview RowCommand event
C#
if(e.CommandName=="delete")
    {
       //code here
    }
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900