Search code examples
asp.netasp.net-mvcwebgrid

Aligning WebGrid headers ASP.net MVC


I need to set the text alignment for individual column headers in the ASP.net WebGrid. Found this, MVC3 WebGrid header alignment and various other people asking the same question, but no real satisfactory answer.

Not really up for replacing it with another grid unless it looks EXACTLY the same, takes the same parameters etc. Already been through another grid and made it work but the pagination UI controls were different and there was no control over the footer style, or cell style

Up for inheriting from WebGrid and rolling my own - but I am not a CSS/HTML expert AT ALL. IS there an easy way?


Solution

  • In the end, because I wanted this behaviour for any column in any grid in the web app (and because I am very comfortable with C# and reflection) I sub-classed WebGrid and created our own version which does allow styles to be specified when the grid is set up.

    Because of how WebGrid is written, it did involve pulling out a couple of the private methods via a disassembler, so it may not be to everyone's taste, but I now have exactly what I wanted.