Hi ucrhlyn,
Check this example. Now please take its reference and correct your code.
HTML
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.2/css/bootstrap.min.css" />
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js"></script>
<script type="text/javascript">
$(function () {
$("[id*=table_groups] input[type=checkbox]").click(function () {
if ($(this).is(":checked")) {
$("[id*=table_groups] input[type=checkbox]").removeAttr("checked");
$(this).attr("checked", "checked");
}
});
});
</script>
<table class="table table-bordered dataTable no-footer" id="table_groups" role="grid">
<thead>
<tr role="row">
<th class="warning sorting_disabled" rowspan="1" colspan="1" aria-label="&nbsp;" style="width: 44px;"> </th>
<th class="warning sorting_asc" tabindex="0" aria-controls="table_groups" rowspan="1" colspan="1" aria-sort="ascending" aria-label=" Group Name : activate to sort column ascending" style="width: 168px;">Group Name </th>
<th class="warning sorting" tabindex="0" aria-controls="table_groups" rowspan="1" colspan="1" aria-label=" Group Description : activate to sort column ascending" style="width: 559px;">Group Description </th>
<th class="warning sorting" tabindex="0" aria-controls="table_groups" rowspan="1" colspan="1" aria-label=" Active Users : activate to sort column ascending" style="width: 150px;">Active Users </th>
</tr>
</thead>
<asp:Repeater runat="server" ID="rptgroupmanager" OnItemDataBound="rptgroupmanager_ItemDataBound">
<ItemTemplate>
<tbody>
<tr role="row" class="odd">
<td class="text-center">
<asp:CheckBox ID="chkSelect" runat="server" />
</td>
<td class="sorting_1">
<asp:Label runat="server" ID="lblgroupname" Text='<%# Eval("Group_Name")%>'></asp:Label>
</td>
<td>
<asp:Label runat="server" ID="lblgroupdescription"><%# Eval("Description")%></asp:Label>
</td>
<td>
<asp:Label runat="server" ID="Label1"></asp:Label>
<label><span runat="server" id="spn_usercount">0</span> User</label>
</td>
</tr>
</tbody>
</ItemTemplate>
</asp:Repeater>
<asp:Label runat="server" ID="lblMessage" Visible="true"></asp:Label>
<asp:Label runat="server" ID="lbldeletegroup" Visible="true"></asp:Label>
</table>
<br />
<asp:Button Text="Get Checked" runat="server" OnClick="getCheckedRow" />
Code
C#
protected void Page_Load(object sender, EventArgs e)
{
if (!this.IsPostBack)
{
System.Data.DataTable dt = new System.Data.DataTable();
dt.Columns.AddRange(new System.Data.DataColumn[3] {
new System.Data.DataColumn("Id"),
new System.Data.DataColumn("Group_Name"),
new System.Data.DataColumn("Description") });
dt.Rows.Add(1, "Admin", "Description 1");
dt.Rows.Add(2, "Super-Admin", "Description 2");
dt.Rows.Add(3, "User", "Description 3");
rptgroupmanager.DataSource = dt;
rptgroupmanager.DataBind();
}
}
protected void rptgroupmanager_ItemDataBound(object sender, RepeaterItemEventArgs e)
{
if ((CheckBox)e.Item.FindControl("chkSelect") != null)
{
((CheckBox)e.Item.FindControl("chkSelect")).Attributes.Add("myName", ((Label)e.Item.FindControl("Label1")).Text);
}
}
protected void getCheckedRow(object sender, EventArgs e)
{
string value = "";
foreach (RepeaterItem item in rptgroupmanager.Items)
{
CheckBox chk = item.FindControl("chkSelect") as CheckBox;
Label lblgroupname = item.FindControl("lblgroupname") as Label;
if (chk.Checked)
{
value = lblgroupname.Text;
break;
}
}
if (value.ToLower() == "Super-Admin".ToLower())
{
string cdmessage;
cdmessage = "Sorry you cant edit the super admin";
ClientScript.RegisterStartupScript(GetType(), "alert", (Convert.ToString("alert('") + cdmessage) + "');", true);
return;
}
}
VB.Net
Protected Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs) Handles Me.Load
If Not Me.IsPostBack Then
Dim dt As Data.DataTable = New Data.DataTable()
dt.Columns.AddRange(New Data.DataColumn(2) {
New Data.DataColumn("Id"),
New Data.DataColumn("Group_Name"),
New Data.DataColumn("Description")})
dt.Rows.Add(1, "Admin", "Description 1")
dt.Rows.Add(2, "Super-Admin", "Description 2")
dt.Rows.Add(3, "User", "Description 3")
rptgroupmanager.DataSource = dt
rptgroupmanager.DataBind()
End If
End Sub
Protected Sub rptgroupmanager_ItemDataBound(ByVal sender As Object, ByVal e As RepeaterItemEventArgs)
If CType(e.Item.FindControl("chkSelect"), CheckBox) IsNot Nothing Then
CType(e.Item.FindControl("chkSelect"), CheckBox).Attributes.Add("myName", CType(e.Item.FindControl("Label1"), Label).Text)
End If
End Sub
Protected Sub getCheckedRow(ByVal sender As Object, ByVal e As EventArgs)
Dim value As String = ""
For Each item As RepeaterItem In rptgroupmanager.Items
Dim chk As CheckBox = TryCast(item.FindControl("chkSelect"), CheckBox)
Dim lblgroupname As Label = TryCast(item.FindControl("lblgroupname"), Label)
If chk.Checked Then
value = lblgroupname.Text
Exit For
End If
Next
If value.ToLower() = "Super-Admin".ToLower() Then
Dim cdmessage As String
cdmessage = "Sorry you cant edit the super admin"
ClientScript.RegisterStartupScript([GetType](), "alert", Convert.ToString("alert('") & cdmessage & "');", True)
Return
End If
End Sub
Screenshot
