Karthik
Karthik

Reputation: 207

How to change the property values after getting from database

Here is my code

 private bool isactive=true;
    public bool IsActive
    {
        get { return isactive; }
        set { isactive = value; }
    }

I will get True,True,True,False,True,False for grid column from database .I want to replace True with Active and False with InActive in my Grid . like

 `if(isactive==true){isactive="Active"}` else{isactive="InActive"}

Instead of true false from db i want to put Active and InActive in my grid view display. I trid it but no solution can u people help me through this

Upvotes: 0

Views: 362

Answers (3)

Nilesh Gajare
Nilesh Gajare

Reputation: 6398

You can manipulate data in your View for eg

if(Model.IsActive==true)
 {
    <label>Active</label>
 }
else
 {
    <label>InActive</label>
 }

Upvotes: 0

Bart Beyers
Bart Beyers

Reputation: 3384

I think you're going to have to use another property to display the values in your grid, because now you are trying to assign a string value to a boolean property.

private bool isactive=true;
public bool IsActive
{
    get { return isactive; }
    set { isactive = value; }
}
public string IsActiveText
{
    get { return IsActive? "Active":"Inactive"; }
}

Then use the property IsActiveText in your view like this:

 columns.Bound(p => p.IsActiveText).Title("Status");

Upvotes: 2

Manoj
Manoj

Reputation: 634

You can update you view like this:

@if(Model.IsActive)
{
<span>Active</span>
}
else
{
<span>InActive</span>
}

Upvotes: 0

Related Questions