Solved

GridMVC

Posted on 2014-02-10
5
966 Views
Last Modified: 2014-02-11
I want to add if qty >1 then qty / Price else just show price

how can I do this within the grid.

I cannot do it in the storedprocedure because the price is int not a string with my mvc project.

  @Html.Grid(Model).Named("Grid").Columns(columns => 
                    {
                            columns.Add(c => c.ItemDescription).Titled("Description").SetWidth(850);
                        columns.Add(c => c.ScanPrice).Titled("Price").Css("money").SetWidth(200).Direction.Equals("right");
                        columns.Add(c => c.BasePrice).Titled("qty").Css("money").SetWidth(200);
                         columns.Add(c => c.CreatedDate).Titled("Created Date").SetWidth(200).Format("{0:dd-MMM-yyyy}"); 
                                        }).WithPaging(10).Sortable(true)

Open in new window

0
Comment
Question by:sevensnake77
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
5 Comments
 
LVL 11

Expert Comment

by:Mihai Stancescu
ID: 39849348
Hi,

You can use a viewmodel or add a property on your model to reflect that behaviour and ignore it for the database if you're using codefirst.


Regards,
Mishu
0
 
LVL 23

Accepted Solution

by:
Ioannis Paraskevopoulos earned 500 total points
ID: 39849471
Hi,

First of all i need to ask... What figure would qty/Price be? Do you mean Price/qty? As in show the price for each item? If this is the case, then having Price/qty would be correct always, no matter what the qty is, as Price/1 = Price.

But then, i will assume you do actually want qty/Price. You may try RenderValueAs

@Html.Grid(Model).Named("Grid").Columns
(columns => 
    {
        columns.Add(c => c.ItemDescription).Titled("Description").SetWidth(850);
        columns.Add(c => c.ScanPrice).Titled("Price").Css("money").SetWidth(200).Direction.Equals("right");
        columns.Add(c => c.BasePrice).Titled("qty").Css("money").SetWidth(200);
        columns.Add(c => c.CreatedDate).Titled("Created Date").SetWidth(200).Format("{0:dd-MMM-yyyy}"); 
        columns.Add().RenderValueAs(x => x.Qty == 1 ? x.Price.ToString() : (x.Qty / x.Price).ToString()).Titled("YourColumnName");
    }
).WithPaging(10).Sortable(true)
                                  

Open in new window


Check the last column in my example.

Giannis
0
 
LVL 9

Author Comment

by:sevensnake77
ID: 39850337
(x.Qty / x.Price).ToString()

Open in new window


this part is dividing  instead of using the slash as a empty string.
0
 
LVL 23

Expert Comment

by:Ioannis Paraskevopoulos
ID: 39850377
I thought you wanted to divide. If you just wanted to show a string literal then:

columns.Add().RenderValueAs(x => x.Qty == 1 ? "Price" : "Qty / Price").Titled("YourColumnName");

Open in new window


Giannis
0
 
LVL 9

Author Closing Comment

by:sevensnake77
ID: 39850378
I just convert / to "/" and it worked out. Thanks
0

Featured Post

On Demand Webinar - Networking for the Cloud Era

This webinar discusses:
-Common barriers companies experience when moving to the cloud
-How SD-WAN changes the way we look at networks
-Best practices customers should employ moving forward with cloud migration
-What happens behind the scenes of SteelConnect’s one-click button

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Reactjs with .NET 3 127
Learning About The VB.NET TableLayoutPanel Control 5 42
Shared Service Environment 2 54
How do you think this website does searches? 5 35
Recently while returning home from work my wife (another .NET developer) was murmuring something. On further poking she said that she has been assigned a task where she has to serialize and deserialize objects and she is afraid of serialization. Wha…
A long time ago (May 2011), I have written an article showing you how to create a DLL using Visual Studio 2005 to be hosted in SQL Server 2005. That was valid at that time and it is still valid if you are still using these versions. You can still re…
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…

751 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question