Solved

GridMVC

Posted on 2014-02-10
5
934 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

Free Tool: Postgres Monitoring System

A PHP and Perl based system to collect and display usage statistics from PostgreSQL databases.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

The object model of .Net can be overwhelming at times – so overwhelming that quite trivial tasks often take hours of research. In this case, the task at hand was to populate the datagrid from SQL Server database in Visual Studio 2008 Windows applica…
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 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…

735 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