[RESOLVED]what is equivalent of RowDataBound event of Web Form gridviews in MVC grids ?


I am new-by on MVC. I have developed a web application on Web Forms which is heavily data driven from a database.  So that i had to use Gridview control in many pages. The beauty of gridview control for me is that i am able to access any controls on RowDatabound,
then i can change them in different ways (colors, visibility, formatting etc) depending on the business logic.

As far as I know, MVC has totally different life cycle where I cannot find any "rowDataBound" event. How would I change controls (colors, visibility etc) in grids depending on the business logic. Say that I have very small grid and I need to change TextBox
color into "RED" if gridview Rownumber is greater then 10? Where should we consider all these logics in MVC?


If you are using the WebGrid class, you can apply simply logic in the format parameter. For example, if you wanted to return red if the Amount property/column is greater than 10, yu can do it like this:

    columns: grid.Columns(
        grid.Column("Amount", "Amount", format: @<span style="color:@(item.Amount > 10 ? "red;" : "black;)">@item.Amount</span>)

Leave a Reply