HorizontalAlign.Center not working in GridView

I think your other styles overriding your new styles.

You can do something like this

Try adding a CSS class to your gridview from your ASPX code, and assign following styles to your class.

 <asp:GridView CssClass="grid" runat="server">
    <!-- your options -->
 </asp:GridView>

.grid td, .grid th{
  text-align:center;
}

You can add CSS class from code behind also.. MSDN LINK

This will set all your columns text to center in your gridview


Give ItemStyle-HorizontalAlign="Center" for any field like bound field or Templatefield.

code:

<asp:TemplateField HeaderText="Something"  ItemStyle-HorizontalAlign="Center" >

 or

<asp:BoundField DataField="" HeaderText="" ItemStyle-HorizontalAlign="Center">

Tags:

C#

.Net

Asp.Net