gridview 表头如何居中 10
已经设置了,属性HeaderStyle为CENTER,仍然不居中,代码如下<asp:GridViewID="GridView1"runat="server"AutoGen...
已经设置了,属性HeaderStyle为CENTER,仍然不居中,代码如下
<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False"
CellPadding ="4">
<Columns >
<asp:BoundField DataField="Title" HeaderText="123123">
</asp:BoundField>
<asp:BoundField DataField="D" HeaderText="1">
<HeaderStyle HorizontalAlign="Center" />
</asp:BoundField>
</Columns>
</asp:GridView>
求解决办法,就是在GRIDVIEW属性里设计的CENTER
用了你们的方法还是不行啊,郁闷。。 展开
<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False"
CellPadding ="4">
<Columns >
<asp:BoundField DataField="Title" HeaderText="123123">
</asp:BoundField>
<asp:BoundField DataField="D" HeaderText="1">
<HeaderStyle HorizontalAlign="Center" />
</asp:BoundField>
</Columns>
</asp:GridView>
求解决办法,就是在GRIDVIEW属性里设计的CENTER
用了你们的方法还是不行啊,郁闷。。 展开
6个回答
推荐于2018-05-10 · 知道合伙人数码行家
可以叫我表哥
知道合伙人数码行家
向TA提问 私信TA
知道合伙人数码行家
采纳数:25897
获赞数:1464972
2010年毕业于北京化工大学北方学院计算机科学与技术专业毕业,学士学位,工程电子技术行业4年从业经验。
向TA提问 私信TA
关注
展开全部
vs 2008
Private Sub tableHeadSet()
'/* set the table head */
Dim tcHeader As TableCellCollection = GridView1.HeaderRow.Cells
'第一行表头
tcHeader.Clear()
tcHeader.Add(New TableHeaderCell())
tcHeader(0).BackColor = Drawing.Color.DarkBlue
tcHeader(0).ForeColor = Drawing.Color.White
tcHeader(0).Height = 30
tcHeader(0).Attributes.Add("colspan", "16") '跨Column
'tcHeader(0).Font.Size = 9
'tcHeader(0).Font.Bold = False
tcHeader(0).Text = "采油井参数显示</th></tr><tr>"
'第二行表头
tcHeader.Add(New TableHeaderCell())
tcHeader(1).BackColor = Drawing.Color.DarkMagenta
tcHeader(1).ForeColor = Drawing.Color.White
tcHeader(1).HorizontalAlign = HorizontalAlign.Center
tcHeader(1).Width = 150
tcHeader(1).Text = "油井名称"
tcHeader.Add(New TableHeaderCell())
tcHeader(2).BackColor = Drawing.Color.DarkGreen
tcHeader(2).ForeColor = Drawing.Color.White
tcHeader(2).HorizontalAlign = HorizontalAlign.Center
tcHeader(2).Width = 140
tcHeader(2).Text = "巡井时间"
tcHeader.Add(New TableHeaderCell())
tcHeader(3).BackColor = Drawing.Color.DarkMagenta
tcHeader(3).ForeColor = Drawing.Color.White
tcHeader(3).HorizontalAlign = HorizontalAlign.Center
tcHeader(3).Width = 80
tcHeader(3).Text = "油井状态"
tcHeader.Add(New TableHeaderCell())
tcHeader(4).BackColor = Drawing.Color.DarkGreen
tcHeader(4).HorizontalAlign = HorizontalAlign.Center
tcHeader(4).ForeColor = Drawing.Color.White
tcHeader(4).Width = 70
tcHeader(4).Text = "冲程(m)"
tcHeader.Add(New TableHeaderCell())
tcHeader(5).BackColor = Drawing.Color.DarkMagenta
tcHeader(5).ForeColor = Drawing.Color.White
tcHeader(5).HorizontalAlign = HorizontalAlign.Center
tcHeader(5).Width = 90
tcHeader(5).Text = "冲次(n/M)"
tcHeader.Add(New TableHeaderCell())
tcHeader(6).BackColor = Drawing.Color.DarkGreen
tcHeader(6).ForeColor = Drawing.Color.White
tcHeader(6).HorizontalAlign = HorizontalAlign.Center
tcHeader(6).Width = 80
tcHeader(6).Text = "最大载荷(KN)"
tcHeader.Add(New TableHeaderCell())
tcHeader(7).BackColor = Drawing.Color.DarkMagenta
tcHeader(7).ForeColor = Drawing.Color.White
tcHeader(7).HorizontalAlign = HorizontalAlign.Center
tcHeader(7).Width = 80
tcHeader(7).Text = "最小载荷(KN)"
tcHeader.Add(New TableHeaderCell())
tcHeader(8).BackColor = Drawing.Color.DarkGreen
tcHeader(8).ForeColor = Drawing.Color.White
tcHeader(8).HorizontalAlign = HorizontalAlign.Center
tcHeader(8).Width = 70
tcHeader(8).Text = "A相最大电流(A)"
tcHeader.Add(New TableHeaderCell())
tcHeader(9).BackColor = Drawing.Color.DarkMagenta
tcHeader(9).ForeColor = Drawing.Color.White
tcHeader(9).HorizontalAlign = HorizontalAlign.Center
tcHeader(9).Width = 70
tcHeader(9).Text = "A相最小电流(A)"
tcHeader.Add(New TableHeaderCell())
tcHeader(10).BackColor = Drawing.Color.DarkGreen
tcHeader(10).ForeColor = Drawing.Color.White
tcHeader(10).HorizontalAlign = HorizontalAlign.Center
tcHeader(10).Width = 70
tcHeader(10).Text = "Uab电压(V)"
tcHeader.Add(New TableHeaderCell())
tcHeader(11).BackColor = Drawing.Color.DarkMagenta
tcHeader(11).ForeColor = Drawing.Color.White
tcHeader(11).HorizontalAlign = HorizontalAlign.Center
tcHeader(11).Width = 70
tcHeader(11).Text = "Ubc电压(V)"
tcHeader.Add(New TableHeaderCell())
tcHeader(12).BackColor = Drawing.Color.DarkGreen
tcHeader(12).ForeColor = Drawing.Color.White
tcHeader(12).HorizontalAlign = HorizontalAlign.Center
tcHeader(12).Width = 70
tcHeader(12).Text = "Uca电压(V)"
tcHeader.Add(New TableHeaderCell())
tcHeader(13).BackColor = Drawing.Color.DarkMagenta
tcHeader(13).ForeColor = Drawing.Color.White
tcHeader(13).HorizontalAlign = HorizontalAlign.Center
tcHeader(13).Width = 70
tcHeader(13).Text = "A相电流(A)"
tcHeader.Add(New TableHeaderCell())
tcHeader(14).BackColor = Drawing.Color.DarkGreen
tcHeader(14).ForeColor = Drawing.Color.White
tcHeader(14).HorizontalAlign = HorizontalAlign.Center
tcHeader(14).Width = 70
tcHeader(14).Text = "B相电流(A)"
tcHeader.Add(New TableHeaderCell())
tcHeader(15).BackColor = Drawing.Color.DarkMagenta
tcHeader(15).ForeColor = Drawing.Color.White
tcHeader(15).HorizontalAlign = HorizontalAlign.Center
tcHeader(15).Width = 70
tcHeader(15).Text = "C相电流(A)"
tcHeader.Add(New TableHeaderCell())
tcHeader(16).BackColor = Drawing.Color.DarkGreen
tcHeader(16).ForeColor = Drawing.Color.White
tcHeader(16).HorizontalAlign = HorizontalAlign.Center
tcHeader(16).Width = 80
tcHeader(16).Text = "井口压力(Mpa)</th></tr><tr>"
End Sub
要想使表头字体居中,要注意表头各列列宽,表头总列宽,才可以达到完美。
GridView1.Width = 1400
Private Sub tableHeadSet()
'/* set the table head */
Dim tcHeader As TableCellCollection = GridView1.HeaderRow.Cells
'第一行表头
tcHeader.Clear()
tcHeader.Add(New TableHeaderCell())
tcHeader(0).BackColor = Drawing.Color.DarkBlue
tcHeader(0).ForeColor = Drawing.Color.White
tcHeader(0).Height = 30
tcHeader(0).Attributes.Add("colspan", "16") '跨Column
'tcHeader(0).Font.Size = 9
'tcHeader(0).Font.Bold = False
tcHeader(0).Text = "采油井参数显示</th></tr><tr>"
'第二行表头
tcHeader.Add(New TableHeaderCell())
tcHeader(1).BackColor = Drawing.Color.DarkMagenta
tcHeader(1).ForeColor = Drawing.Color.White
tcHeader(1).HorizontalAlign = HorizontalAlign.Center
tcHeader(1).Width = 150
tcHeader(1).Text = "油井名称"
tcHeader.Add(New TableHeaderCell())
tcHeader(2).BackColor = Drawing.Color.DarkGreen
tcHeader(2).ForeColor = Drawing.Color.White
tcHeader(2).HorizontalAlign = HorizontalAlign.Center
tcHeader(2).Width = 140
tcHeader(2).Text = "巡井时间"
tcHeader.Add(New TableHeaderCell())
tcHeader(3).BackColor = Drawing.Color.DarkMagenta
tcHeader(3).ForeColor = Drawing.Color.White
tcHeader(3).HorizontalAlign = HorizontalAlign.Center
tcHeader(3).Width = 80
tcHeader(3).Text = "油井状态"
tcHeader.Add(New TableHeaderCell())
tcHeader(4).BackColor = Drawing.Color.DarkGreen
tcHeader(4).HorizontalAlign = HorizontalAlign.Center
tcHeader(4).ForeColor = Drawing.Color.White
tcHeader(4).Width = 70
tcHeader(4).Text = "冲程(m)"
tcHeader.Add(New TableHeaderCell())
tcHeader(5).BackColor = Drawing.Color.DarkMagenta
tcHeader(5).ForeColor = Drawing.Color.White
tcHeader(5).HorizontalAlign = HorizontalAlign.Center
tcHeader(5).Width = 90
tcHeader(5).Text = "冲次(n/M)"
tcHeader.Add(New TableHeaderCell())
tcHeader(6).BackColor = Drawing.Color.DarkGreen
tcHeader(6).ForeColor = Drawing.Color.White
tcHeader(6).HorizontalAlign = HorizontalAlign.Center
tcHeader(6).Width = 80
tcHeader(6).Text = "最大载荷(KN)"
tcHeader.Add(New TableHeaderCell())
tcHeader(7).BackColor = Drawing.Color.DarkMagenta
tcHeader(7).ForeColor = Drawing.Color.White
tcHeader(7).HorizontalAlign = HorizontalAlign.Center
tcHeader(7).Width = 80
tcHeader(7).Text = "最小载荷(KN)"
tcHeader.Add(New TableHeaderCell())
tcHeader(8).BackColor = Drawing.Color.DarkGreen
tcHeader(8).ForeColor = Drawing.Color.White
tcHeader(8).HorizontalAlign = HorizontalAlign.Center
tcHeader(8).Width = 70
tcHeader(8).Text = "A相最大电流(A)"
tcHeader.Add(New TableHeaderCell())
tcHeader(9).BackColor = Drawing.Color.DarkMagenta
tcHeader(9).ForeColor = Drawing.Color.White
tcHeader(9).HorizontalAlign = HorizontalAlign.Center
tcHeader(9).Width = 70
tcHeader(9).Text = "A相最小电流(A)"
tcHeader.Add(New TableHeaderCell())
tcHeader(10).BackColor = Drawing.Color.DarkGreen
tcHeader(10).ForeColor = Drawing.Color.White
tcHeader(10).HorizontalAlign = HorizontalAlign.Center
tcHeader(10).Width = 70
tcHeader(10).Text = "Uab电压(V)"
tcHeader.Add(New TableHeaderCell())
tcHeader(11).BackColor = Drawing.Color.DarkMagenta
tcHeader(11).ForeColor = Drawing.Color.White
tcHeader(11).HorizontalAlign = HorizontalAlign.Center
tcHeader(11).Width = 70
tcHeader(11).Text = "Ubc电压(V)"
tcHeader.Add(New TableHeaderCell())
tcHeader(12).BackColor = Drawing.Color.DarkGreen
tcHeader(12).ForeColor = Drawing.Color.White
tcHeader(12).HorizontalAlign = HorizontalAlign.Center
tcHeader(12).Width = 70
tcHeader(12).Text = "Uca电压(V)"
tcHeader.Add(New TableHeaderCell())
tcHeader(13).BackColor = Drawing.Color.DarkMagenta
tcHeader(13).ForeColor = Drawing.Color.White
tcHeader(13).HorizontalAlign = HorizontalAlign.Center
tcHeader(13).Width = 70
tcHeader(13).Text = "A相电流(A)"
tcHeader.Add(New TableHeaderCell())
tcHeader(14).BackColor = Drawing.Color.DarkGreen
tcHeader(14).ForeColor = Drawing.Color.White
tcHeader(14).HorizontalAlign = HorizontalAlign.Center
tcHeader(14).Width = 70
tcHeader(14).Text = "B相电流(A)"
tcHeader.Add(New TableHeaderCell())
tcHeader(15).BackColor = Drawing.Color.DarkMagenta
tcHeader(15).ForeColor = Drawing.Color.White
tcHeader(15).HorizontalAlign = HorizontalAlign.Center
tcHeader(15).Width = 70
tcHeader(15).Text = "C相电流(A)"
tcHeader.Add(New TableHeaderCell())
tcHeader(16).BackColor = Drawing.Color.DarkGreen
tcHeader(16).ForeColor = Drawing.Color.White
tcHeader(16).HorizontalAlign = HorizontalAlign.Center
tcHeader(16).Width = 80
tcHeader(16).Text = "井口压力(Mpa)</th></tr><tr>"
End Sub
要想使表头字体居中,要注意表头各列列宽,表头总列宽,才可以达到完美。
GridView1.Width = 1400
展开全部
居中直接一句align就可以居中,但是如果想实现表头居中,内容靠左的话(靠右修改为"text-align:right;),可以用这种方式实现:
align : 'center',
formatter: function(value,row,index){
if(value!=null){
return '<div style="text-align:left;width:100%">'+value+"</div>";
}
},
相当于在datagrid封装好的居中div层里面再封装一层,就可以实现了
align : 'center',
formatter: function(value,row,index){
if(value!=null){
return '<div style="text-align:left;width:100%">'+value+"</div>";
}
},
相当于在datagrid封装好的居中div层里面再封装一层,就可以实现了
本回答被网友采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
表头是默认居中的,你的代码明明是要让行里面的内容居中,把<HeaderStyle HorizontalAlign="Center" />换成<ItemStyle HorizontalAlign="Center" />就可以居中显示了,记得 追加。。。哈哈
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
你可以将此列转换为模板列 即转换成templateField后再将 controlStyle与HeaderStyle中的宽度设定为50px,行剧中后再试试!
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
<HeaderStyle HorizontalAlign="Center" />加这个在 </Columns></asp:GridView>之间
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询