ASP.net Gridview Highlights Multiple Column Values

I have a gridview that shows, for example, the statistics of a baseball team. This is a standard grid of sports statistics - the rows show statistics for each player, and the columns show a specific indicator for each player.

Easy enough. But what I would like to do is style (highlight or bold) Max or Min (group leader) of each stat column. For example, player A can only lead one or two categories, so we cannot create a whole line style. If player A simply leads the team in outs, I just want to set the number of strikeouts he has had (only for this cell).

What is the best way to handle this? Do SQL Server all the work and act, become EVERY stat of each player, effectively doubling the number of columns (for example, col: AB, col: ABRank). Or can I let this rowdatabound gridview event handle this?

If I chose the latter, I think that I will get the Max of each statistic category from the datatable before binding (for example, save them in a local variable), and then in rowdataound, if they match the value, apply the style.

+4
source share
3 answers

You have already answered your question, which, incidentally, gave me the answer.

Or can I let the rowdatabound event gridview handle this?

If I chose the latter, I would have thought to get Max. each statistic from the data category before binding (for example, store them in a local variable), then in rowdataound, if they match the value, apply the style.

+2
source

There is an option that you did not mention. You can use javascript clientside to highlight. It should be fairly simple to perform on the table am to display the highest values ​​in the column.

+2
source

Depending on what you are doing, you probably have a certain number of columns to which you are bound.

I would use LINQ on your DataSource, before binding it, for each type you want to use max, for example:

// create a global variable to hold the data int _maxHomeRuns = 0; // Then before you bind the datasource, find out the max of each stat _maxHomeRuns = baseballStats.Max(i => i.HomeRuns); // get the max // Then in your template columns Label control DataBinding method if ((int)(Eval("HomeRuns")) == _maxHomeRuns) { // Assign the style you want ((Label)(sender)).CssClass = "MaxCellStyle"; } 

I would not use RowDataBinding , do it at the OnDataBinding control OnDataBinding , so that you look at the checks specifically for the control, so you do not need to look for the controls in the string.

+2
source

Source: https://habr.com/ru/post/1345779/


All Articles