Click here to Skip to main content
15,907,906 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi all,

I have a grid view control that displays one column and I want to change the style of that column. I want its text-align to be set to the center. I tried to put it in adiv but it occurred in the whole grid.

How can I make that?

Thanks
Posted
Updated 23-Jan-11 0:32am
v2

Hi,
You can use GridView ItemStyle property to align your text. For GridView BoundField or TemplateField there in as property called ItemStyle HorizontalAlign, You can write ItemStyle-HorizontalAlign="Center"
As for example,
VB
<asp:BoundField ItemStyle-HorizontalAlign="Center" DataField="ProductID" HeaderText="ProductID" ReadOnly="True"
                              SortExpression="ProductID" />

Hope this will help !
 
Share this answer
 
See here:
MSIL
GridView Examples for ASP.NET 2.0: Formatting the GridView

[^].

Not bang up to date but it'll get you going.
 
Share this answer
 
Two ways,
1. Find the column using index/column-name from the grid and then apply css specific to this.
2. You can go to column/cell level using datagrid's ItemDatabound or gridview's RowDatabound and apply css at then. Have a look at this article[^] for the same.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900