0

I'm new to creating reports in ASP.net and I would like to know if there's anything that can display data differently than what's stored in the DB.

Here's my example. I have a column called Active and in the DB table, 0 represents Active, -1 represents InActive.

In my report, when showing whether or not a listing is Active, I'd rather have the words Active and Inactive rather than 0 and -1.

Would this be found in custom expressions? I'm not sure where to begin...

3 Answers 3

2

Alternate solution: If you don't want to model it, then easiest would be to change your db query and return "Inactive" and "Active" string when that column is -1 and -0. You can do this through "CASE WHEN..." if its MS SQL Server.

Sign up to request clarification or add additional context in comments.

Comments

1

If you are using SSRS for reporting or Crystal Reports, you can replace text at run-time. In Crystal Reports, you can add a Formula Field with IF ... ELSE condition.

2 Comments

I'm not using Crystal Reports unfortunately. I'm working with a legacy system that my company has in place...
If you are just displaying on GridView control, you can simply replace the cell value when the Grid is being filled. To do this, write the replace code in GridView's RowCreated event.
0

Model your db table to a class object representation. E.g.:

public class MyDataModel
{
    public int Active { get; set; }

    public string ActiveDisplay 
    {
      get 
      {
        return (this.Active==-1) ? "Inactive" : "Active";
      }
    }
}

When you get data from the database, create a collection of your model that will load all the rows from the returned data; e.g.

var myData = new List<MyDataModel>()

You can now bind this collection of model objects to a data grid and display the "ActiveDisplay" property instead of "Active" property.

3 Comments

Isn't there a way to do this with expressions? Something like =Iif(Fields!Active.Value == 0, Fields!Active.Value = "Active")
Not sure what you meant by expressions. If you don't want to model it, then easiest would be to change your db query and return "Inactive" and "Active" string when that column is -1 and -0. You can do this through "CASE WHEN..." if its MS SQL Server.
Thanks man! I just looked up and did it with CASE WHEN and it worked great! Any way you can repost that solution as an answer so I can one up and check mark it?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.