Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

GridMVC

Posted on 2014-02-10
5
Medium Priority
?
1,045 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:Seven price
[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 2000 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:Seven price
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:Seven price
ID: 39850378
I just convert / to "/" and it worked out. Thanks
0

Featured Post

How To Reduce Deployment Times With Pre-Baked AMIs

Even if we can't include all the files in the base image, we can sometimes include some of the larger files that we would otherwise have to download, and we can also sometimes remove the most time-consuming steps. This can help a lot with reducing deployment times.

Question has a verified solution.

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

Summary Displaying images in RichTextBox is a common requirement with limited solutions available. Pasting through clipboard or embedding into RTF content only support static images.  This article describes how to insert Windows control objects int…
Today I had a very interesting conundrum that had to get solved quickly. Needless to say, it wasn't resolved quickly because when we needed it we were very rushed, but as soon as the conference call was over and I took a step back I saw the correct …
Visualize your data even better in Access queries. Given a date and a value, this lesson shows how to compare that value with the previous value, calculate the difference, and display a circle if the value is the same, an up triangle if it increased…
In this video, Percona Solution Engineer Dimitri Vanoverbeke discusses why you want to use at least three nodes in a database cluster. To discuss how Percona Consulting can help with your design and architecture needs for your database and infras…

671 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