Hi ramco1917,
Please refer below sample,
HTML
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<asp:Repeater ID="rptStudents" runat="server" OnItemDataBound="OnItemDataBound">
<HeaderTemplate>
<table class="table">
<tr>
<td>StudentId</td>
<td>StudentName</td>
<td>Status</td>
</tr>
</HeaderTemplate>
<ItemTemplate>
<tr>
<td>
<asp:Label ID="lblId" Text='<%#Eval("StudentId") %>' runat="server" /></td>
<td>
<asp:Label ID="lblName" Text='<%#Eval("StudentName") %>' runat="server" /></td>
<td>
<div class="btn-group btn-group-toggle" data-toggle="buttons">
<label id="pnlP" runat="server" style="margin-right: 10px">
<asp:RadioButton ID="rb1" GroupName="options" runat="server" Checked="true" Text="P" />
</label>
<label id="pnlA" runat="server">
<asp:RadioButton ID="rb2" GroupName="options" runat="server" Text="A" />
</label>
</div>
</td>
</tr>
</ItemTemplate>
<FooterTemplate>
</table>
</FooterTemplate>
</asp:Repeater>
<style type="text/css">
body {
font-family: Arial;
font-size: 30pt;
}
.radius {
border-radius: 100% !important;
}
.btn.active {
background-color: dodgerblue !important;
border-color: dodgerblue !important;
}
</style>
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.2/css/bootstrap.min.css" />
<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script>
<script type="text/javascript" src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.2/js/bootstrap.min.js"></script>
</form>
</body>
</html>
Namespaces
C#
using System.Data;
using System.Configuration;
using System.Data.SqlClient;
VB.Net
Imports System.Data
Imports System.Configuration
Imports System.Data.SqlClient
Code
C#
protected void Page_Load(object sender, EventArgs e)
{
if (!this.IsPostBack)
{
this.BindRepeater();
}
}
private void BindRepeater()
{
string conString = ConfigurationManager.ConnectionStrings["constr"].ConnectionString;
using (SqlConnection con = new SqlConnection(conString))
{
using (SqlCommand cmd = new SqlCommand("SELECT StudentId, StudentName, Status FROM Students", con))
{
using (SqlDataAdapter sda = new SqlDataAdapter(cmd))
{
DataTable dt = new DataTable();
sda.Fill(dt);
rptStudents.DataSource = dt;
rptStudents.DataBind();
}
}
}
}
protected void OnItemDataBound(object sender, RepeaterItemEventArgs e)
{
if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem)
{
RadioButton rb1 = (e.Item.FindControl("rb1") as RadioButton);
RadioButton rb2 = (e.Item.FindControl("rb2") as RadioButton);
HtmlGenericControl pnlP = (e.Item.FindControl("pnlP") as HtmlGenericControl);
HtmlGenericControl pnlA = (e.Item.FindControl("pnlA") as HtmlGenericControl);
if (rb1.Text.ToUpper() == "A")
{
pnlA.Attributes.Add("class", "btn btn-danger radius");
}
else if(rb1.Text.ToUpper() == "P")
{
pnlA.Attributes.Add("class", "btn btn-success radius");
}
if (rb2.Text.ToUpper() == "A")
{
pnlP.Attributes.Add("class", "btn btn-danger radius");
}
else if (rb2.Text.ToUpper() == "P")
{
pnlP.Attributes.Add("class", "btn btn-success radius");
}
}
}
VB.Net
Protected Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs) Handles Me.Load
If Not Me.IsPostBack Then
Me.BindRepeater()
End If
End Sub
Private Sub BindRepeater()
Dim conString As String = ConfigurationManager.ConnectionStrings("constr").ConnectionString
Using con As SqlConnection = New SqlConnection(conString)
Using cmd As SqlCommand = New SqlCommand("SELECT StudentId, StudentName, Status FROM Students", con)
Using sda As SqlDataAdapter = New SqlDataAdapter(cmd)
Dim dt As DataTable = New DataTable()
sda.Fill(dt)
rptStudents.DataSource = dt
rptStudents.DataBind()
End Using
End Using
End Using
End Sub
Protected Sub OnItemDataBound(ByVal sender As Object, ByVal e As RepeaterItemEventArgs)
If e.Item.ItemType = ListItemType.Item OrElse e.Item.ItemType = ListItemType.AlternatingItem Then
Dim rb1 As RadioButton = (TryCast(e.Item.FindControl("rb1"), RadioButton))
Dim rb2 As RadioButton = (TryCast(e.Item.FindControl("rb2"), RadioButton))
Dim pnlP As HtmlGenericControl = (TryCast(e.Item.FindControl("pnlP"), HtmlGenericControl))
Dim pnlA As HtmlGenericControl = (TryCast(e.Item.FindControl("pnlA"), HtmlGenericControl))
If rb1.Text.ToUpper() = "A" Then
pnlA.Attributes.Add("class", "btn btn-danger radius")
ElseIf rb1.Text.ToUpper() = "P" Then
pnlA.Attributes.Add("class", "btn btn-success radius")
End If
If rb2.Text.ToUpper() = "A" Then
pnlP.Attributes.Add("class", "btn btn-danger radius")
ElseIf rb2.Text.ToUpper() = "P" Then
pnlP.Attributes.Add("class", "btn btn-success radius")
End If
End If
End Sub
Screenshot