简体   繁体   中英

How to change button background color based on database boolean field in ASP.NET using VB.NET?

I want to change the button's background color based on the "Status" field in my database. Where False = Green and True = Red .

I'm using ASP.NET but I don't know how to do it, because I can only access the database from the '.aspx.vb' files.

You can change the background color of Buttons like this.

If (Convert.ToBoolean(reader("status")) = true) Then
    Button1.BackColor = Color.Red
Else
    Button1.BackColor = Color.Green
End If

This snippet's usage is based on looping the Database values with a DataReader .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM