protected void Button1_Click(object sender, EventArgs e) { //Loop through all the rows in gridview foreach (GridViewRow gvrow in gv1.Rows) { //Finiding checkbox control in gridview for particular row CheckBox chkdelete = (CheckBox)gvrow.FindControl("chkdelete"); //Condition to check checkbox selected or not if (chkdelete.Checked) { //Getting email of particular row using datakey value //int mail = Convert.ToInt32(gv1.DataKeys[gvrow.RowIndex].Value); string email = gv1.DataKeys[gvrow.RowIndex]["mail"].ToString(); AccessDataSource1.DeleteParameters["mail"].DefaultValue = email; AccessDataSource1.Delete(); } } }
<asp:GridView ID="gv1" runat="server" DataSourceID="AccessDataSource1" DataKeyNames="mail" CssClass="Gridview" AutoGenerateColumns="False" HeaderStyle-BackColor="#61A6F8" HeaderStyle-Font-Bold="true" HeaderStyle-ForeColor="White" AllowPaging="True"> <Columns> <asp:TemplateField> <ItemTemplate> <asp:CheckBox ID="chkdelete" runat="server"/> </ItemTemplate> </asp:TemplateField> <asp:BoundField DataField="cname" HeaderText="NAME" /> <asp:BoundField DataField="dob" HeaderText="DOB" /> <asp:BoundField DataField="city" HeaderText="CITY" /> <asp:BoundField DataField="mail" HeaderText="EMAIL" /> <asp:BoundField DataField="occu" HeaderText="OCCUPATION" /> </Columns> </asp:GridView> <asp:Button ID="Button1" runat="server" onclick="Button1_Click" Text="Delete" /> <br /> <asp:AccessDataSource ID="AccessDataSource1" runat="server" DataFile="~/Rabiya.mdb" SelectCommand="SELECT [cname], [dob], [city], [mail], [occu] FROM [joining]" DeleteCommand="Delete from joining where mail=@mail"> <DeleteParameters> <asp:Parameter Name="mail" Type="Int32" /> </DeleteParameters> </asp:AccessDataSource>
<script type="text/javascript"> function Confirmationbox() { var result = confirm('Are you sure you want to delete selected User(s)?'); if (result) { return true; } else { return false; } } </script>
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)