Question: I have a gridview and i'm associating the datasource for the grid view dynamically at runtime

I mean 

```
 gridView2.DataSource = titlesArrayList;
 gridView2.DataBind();

```

And i want the data in cells of this grid view to be centered, right now they are left-justified

If i was associating data through 

```
<asp:BoundField />

```

I have this property 

```
ItemStyle-HorizontalAlign="Center"

```

But how can i access this property if the gridview is associated dynamically

I hope u understand my problem

Thanks in anticipation

Answer: 
EDIT:

try

```
        foreach (GridViewRow  row in GridView1.Rows)
        {
            foreach (TableCell cell in row.Cells)
            {
                cell.Attributes.CssStyle["text-align"] = "center";
            }
        }

```
The easiest way is probably from the mark-up. Just assign `HorizontalAlign` to Center in the grid's `RowStyle`. No need to iterate through every cell programmatically.

**Example:**

```
<asp:GridView>
<RowStyle HorizontalAlign="Center" />
<Columns>
...
</Columns>
</asp:GridView>

```