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
C#
//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
C#
ID Anggota
Nama Anggota
Alamat
Nomer Telepon
Tanggal Bergabung
Status Anggota
Saldo (Rp.)
Catatan
#
' class="fa fa-edit btn btn-warning btn-sm" OnClick="LinkButton1_Click" runat="server"> Detail
Sachin SinghRank #66 · 26.2K reputationPosted Jul 4, 2021, 3:07 AM EDT
Sachin SinghRank #66 · 26.2K reputationPosted Jul 4, 2021, 3:30 AM EDT
Sachin SinghRank #66 · 26.2K reputationPosted Jul 4, 2021, 3:57 AM EDT
Sachin SinghRank #66 · 26.2K reputationPosted Jul 4, 2021, 6:58 AM EDT
Tri SetiaRank #4,571 · 337 reputationPosted Jul 4, 2021, 7:13 AM EDT
Tri SetiaRank #4,571 · 337 reputationPosted Jul 4, 2021, 3:24 AM EDT
@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.
Tri SetiaRank #4,571 · 337 reputationPosted Jul 4, 2021, 3:44 AM EDT
@Sachin Singh
still same sir, I'm was try this code get 16 error.
Invalid Expression term 'if' etc
'>Tri SetiaRank #4,571 · 337 reputationPosted Jul 4, 2021, 6:54 AM EDT
Tri SetiaRank #4,571 · 337 reputationPosted Jul 4, 2021, 7:15 AM EDT
- 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 SetiaRank #4,571 · 337 reputationPosted Jul 5, 2021, 7:59 AM EDT
Answer a question in the forums and earn +20 SHARP for every answer.
See unanswered questionsTop experts