In this article we will delete items in a DataList control from the database by selecting RadioButton and CheckBox using a delete Button.
Table Structure
Create table student (sid varchar(50) primary key,sname varchar(50),saddress varchar(50),smarks int,year varchar(50))

Default.aspx code
<%@ Page Language="VB" AutoEventWireup="false" CodeFile="Default.aspx.vb" Inherits="_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>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:label id="Label1" runat="server" Font-Bold="True"></asp:label>
<asp:datalist id="DataList1" runat="server" DataKeyField="sid">
<HeaderTemplate>
<table>
<tr>
<th><font color="red">ID</font></th>
<th><font color="red">Name</font></th>
<th><font color="red">Address</font></th>
<th><font color="red">Marks</font></th>
<th><font color="red">Year</font></th>
</tr>
</HeaderTemplate>
<ItemTemplate>
<tr>
<td><asp:RadioButton ID="r1" Text='<%#container.dataitem("sid")%>' Runat="server">
</asp:RadioButton></td>
<td><%#container.dataitem("sid")%></td>
<td><%#container.dataitem("sname")%></td>
<td><%#container.dataitem("saddress")%></td>
<td><%#container.dataitem("smarks")%></td>
<td><%#container.dataitem("year")%></td>
</tr>
</ItemTemplate>
<HeaderStyle BackColor="#FFCC66" />
<FooterTemplate>
</table>
</FooterTemplate>
</asp:datalist>
<asp:button id="btndelete" runat="server" Text="Select
Radiobutton Delete" Font-Bold="True">
</asp:button>
<hr />
<asp:datalist id="DataList2" runat="server" DataKeyField="sid">
<HeaderTemplate>
<table> <tr>
<th><font color="red">ID</font></th>
<th><font color="red">Name</font></th>
<th><font color="red">Address</font></th>
<th><font color="red">Marks</font></th>
<th><font color="red">Year</font></th>
</tr>
</HeaderTemplate>
<ItemTemplate>
<tr>
<td><asp:CheckBox ID="chkid" Text='<%#container.dataitem("sid")%>' Runat="server"/></td>
<td><%#container.dataitem("sid")%></td>
<td><%#container.dataitem("sname")%></td>
<td><%#container.dataitem("saddress")%></td>
<td><%#container.dataitem("smarks")%></td>
<td><%#container.dataitem("year")%></td>
</tr>
</ItemTemplate>
<HeaderStyle BackColor="#FFCC66" />
<FooterTemplate>
</table>
</FooterTemplate>
</asp:datalist>
<asp:button id="btndelete1" runat="server" Text="Select
CheckBox Delete" Font-Bold="True">
</asp:button>
</div>
</form>
</body>
</html>


Join the conversation! Your thoughts help the community grow.