I am using an ASP Data Grid I am Binding the data field,Header Text dynamically through code behind(c#).
I am also setting the style of the column dynamically all are working fine but one of the Column Horizontal-align.Center is not working .
I have checked if the style is getting overridden but it is not…
This the block of code giving an issue:
BoundField field4 = new BoundField();
field4.DataField = dtdata.Tables[0].Columns["data"].ToString();
field4.HeaderText = "Percentage%";
field4.DataFormatString = "{0:N1}%";
field4.SortExpression = "data";
field4.ItemStyle.HorizontalAlign = HorizontalAlign.Center;
grdMarginGrid.Columns.Add(field4);
Can anyone help me in recognising where the issue is..
Thanks in advance,
Divya.
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.
You can add CSS class from code behind also..
MSDN LINK
This will set all your columns text to center in your gridview