Hi Guys,, I'm trying to make background color in repeater with the condition, data come from database and then bind to repeater. I'm use bootstrap class for the background color.
The condition is :
- If status_anggota "AKTIF" it will show background color green ("text-center bg bg-success") on repeater.
- If status_anggota "TIDAK AKTIF" it will show background color red "text-center bg bg-danger" on repeater.
how to do that ?. Anny help could be appriciate.
This is the code bihind
//This code not working
protected void StatusAnggota()
{
string HtmlStringAktif = "text-center bg bg-success";
string HtmlStringTidakAktif = "text-center bg bg-danger";
using (SqlConnection con = new SqlConnection(koneksi))
{
using (SqlCommand sqlcmd = new SqlCommand())
{
con.Open();
sqlcmd.Connection = con;
sqlcmd.CommandType = CommandType.Text;
sqlcmd.CommandText = "Select * From dbo.tbl_anggota";
using (SqlDataReader rdr = sqlcmd.ExecuteReader())
{
if (rdr.Read())
{
new LiteralControl(HtmlStringAktif = rdr["status_anggota"].ToString());
SqlDataAdapter adp = new SqlDataAdapter(sqlcmd);
DataTable dt = new DataTable();
con.Close();
adp.Fill(dt);
Repeater1.DataSource = dt;
Repeater1.DataBind();
}
else
{
new LiteralControl (HtmlStringTidakAktif = rdr["status_anggota"].ToString());
SqlDataAdapter adp = new SqlDataAdapter(sqlcmd);
DataTable dt = new DataTable();
con.Close();
adp.Fill(dt);
Repeater1.DataSource = dt;
Repeater1.DataBind();
}
}
}
con.Close();
}
}
This is the repeater
ID Anggota
Nama Anggota
Alamat
Nomer Telepon
Tanggal Bergabung
Status Anggota
Saldo (Rp.)
Catatan
#
<%#Eval("id_anggota")%>
<%#Eval("nama_anggota")%>
<%#Eval("alamat")%>
<%#Eval("no_telpon")%>
<%#Eval("tgl_join","{0: dd MMMM yyyy}")%>
<%#Eval("status_anggota")%>
<%#Eval("saldo","{0:Rp 0,00.00}")%>
<%#Eval("catatan")%>
Detail

Tri SetiaPosted Jul 5, 2021, 11:59 AM
Tri SetiaPosted Jul 4, 2021, 11:15 AM
- If status_anggota "AKTIF" it will show background color green ("text-center bg bg-success") on repeater.
- If status_anggota "TIDAK AKTIF" it will show background color red "text-center bg bg-danger" on repeater.
Tri SetiaPosted Jul 4, 2021, 11:13 AM
Sachin SinghPosted Jul 4, 2021, 10:58 AM
Tri SetiaPosted Jul 4, 2021, 10:54 AM
Sachin SinghPosted Jul 4, 2021, 7:57 AM
Tri SetiaPosted Jul 4, 2021, 7:44 AM
@Sachin Singh
still same sir, I'm was try this code get 16 error.
Invalid Expression term 'if' etc
Sachin SinghPosted Jul 4, 2021, 7:30 AM
Tri SetiaPosted Jul 4, 2021, 7:24 AM
@Sachin Singh
I'm was try this your code sir but not working, the code show 16 error.
I'm just change this line on repeater.
Sachin SinghPosted Jul 4, 2021, 7:07 AM