Solved

GridMVC

Posted on 2014-02-10
5
838 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
  • 2
  • 2
5 Comments
 
LVL 11

Expert Comment

by:Mihai Stancescu
Comment Utility
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
Comment Utility
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
Comment Utility
(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
Comment Utility
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
Comment Utility
I just convert / to "/" and it worked out. Thanks
0

Featured Post

Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

Join & Write a Comment

Suggested Solutions

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…
For those of you who don't follow the news, or just happen to live under rocks, Microsoft Research released a beta SDK (http://www.microsoft.com/en-us/download/details.aspx?id=27876) for the Xbox 360 Kinect. If you don't know what a Kinect is (http:…
It is a freely distributed piece of software for such tasks as photo retouching, image composition and image authoring. It works on many operating systems, in many languages.
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…

772 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

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now