Can you easily right-align just one column in a GridView?
I have this
<asp:GridView ID="GridView1" runat="server"></asp:GridView>
It is bound to a DataTable (generated dynamically) that has many columns. I just want the ‘Price’ column to be right-aligned.
(Coming across this problem, I am wondering if I should be printing out HTML <table> instead of using a GridView. Using HTML I would have total control.)
Yes, you can, but I think if you have
AutoGenerateColumnsset to true (which it is by default) then you need to right align the column using theRowDataBoundevent. As a side note, if it’s easier you can setAutoGenerateColumnsto false and use BoundFields which will give you more formatting options and will probably eliminate the need for theRowDataBoundevent.GridView:
Codebehind:
Hope that helps.