dsfasdfadf dsfasdfadf - 1 year ago 69
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;

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


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

I hope u understand my problem

Thanks in anticipation

Answer Source



        foreach (GridViewRow  row in GridView1.Rows)
            foreach (TableCell cell in row.Cells)
                cell.Attributes.CssStyle["text-align"] = "center";
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download