HTML
<asp:Repeater ID="Repeater1" runat="server">
<HeaderTemplate>
<table id = "tblContacts" border="0" cellpadding="0" cellspacing="0">
<tr>
<th>
</th>
<th>
Name
</th>
<th>
Country
</th>
</tr>
</HeaderTemplate>
<ItemTemplate>
<tr>
<td>
<asp:CheckBox Text="" runat="server" />
</td>
<td>
<%#Eval("Name") %>
</td>
<td>
<%#Eval("Country") %>
</td>
</tr>
</ItemTemplate>
<FooterTemplate>
</table>
</FooterTemplate>
</asp:Repeater>
<br />
<asp:Button Text="Submit" runat="server" OnClientClick = "return Validate();" />
<script type = "text/javascript">
function Validate() {
var table = document.getElementById("tblContacts");
var checkboxes = table.getElementsByTagName("input");
for (var i = 0; i < checkboxes.length; i++) {
if (checkboxes[i].type == "checkbox" && checkboxes[i].checked) {
return true;
}
}
alert("Please select at least one record!");
return false;
}
</script>
Code
protected void Page_Load(object sender, EventArgs e)
{
if (!this.IsPostBack)
{
DataTable dt = new DataTable();
dt.Columns.AddRange(new DataColumn[3] { new DataColumn("Id", typeof(int)),
new DataColumn("Name", typeof(string)),
new DataColumn("Country",typeof(string)) });
dt.Rows.Add(1, "John Hammond", "United States");
dt.Rows.Add(2, "Mudassar Khan", "India");
dt.Rows.Add(3, "Suzanne Mathews", "France");
dt.Rows.Add(4, "Robert Schidner", "Russia");
Repeater1.DataSource = dt;
Repeater1.DataBind();
}
}
Namespace
using System.Data;
,