dsfasdfadf dsfasdfadf - 3 months ago 6
ASP.NET (C#) Question

Centering the data in a cell in grid view

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";
            }
        }