Praditha
Praditha

Reputation: 1172

Dynamically added checked attributes C#

I'm new in C# ASP .Net. I've a problem like this:
I've data from database like this:

button_id | button_access
-------------------------
btnSearch | true
btnClear  | true
btnAdd    | false
btnSave   | false

in my view:

@data [data from database]
...
@foreach (chk in data) {
  <input name="btnSearch" type="checkbox" value="@chk.button_id" {???} />
}
...

I think, in {???} I have to insert a condition like:

IF (chk.buttonAccess) {
   //Code to write attribute checked
}

What should I filled in {???} ..?

Upvotes: 0

Views: 213

Answers (1)

Cheng Chen
Cheng Chen

Reputation: 43513

Try this:

@(chk.button_access ? "checked" : "")

Upvotes: 1

Related Questions