HorizontalAlign.Center不工作的GridView [英] HorizontalAlign.Center not working in GridView
问题描述
我使用的是ASP数据网格我绑定的数据字段,标题文字通过动态背后code(C#)。
I am using an ASP Data Grid I am Binding the data field,Header Text dynamically through code behind(c#).
我也设置栏的风格动态所有人都工作正常,但列Horizontal-align.Center之一是行不通的。
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...
code给人一个问题这个块:
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.
您可以做这样的事情。
尝试从您的ASPX code添加CSS类你的GridView,并指定下列样式到您的类。
Try adding a CSS class to your gridview from your ASPX code, and assign following styles to your class.
<asp:GridView CssClass="grid" runat="server">
<!-- your options -->
</asp:GridView>
.grid td, .grid th{
text-align:center;
}
您可以从code添加CSS类也落后..
<一href=\"http://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.webcontrol.cssclass.aspx\">MSDN链接
You can add CSS class from code behind also.. MSDN LINK
这将设置你的所有列文本中心你的GridView
This will set all your columns text to center in your gridview
这篇关于HorizontalAlign.Center不工作的GridView的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!