如何垂直获取GridView标题文本 [英] How to get GridView Header Text vertically
问题描述
我使用网格视图来显示数据,但是我有很多大名字的列,因此它包含更多的屏幕大小。
所以请帮助我如何获得标题文本垂直,以便列没有得到更多的屏幕,我可以显示我的整个网格在同一页面而不滚动。我使用visual studio 2005与vb.net
任何帮助都将被赞赏。
虽然我不得不说,如果所有标题文本都垂直显示,它看起来很难看。
首先,我们需要一个CSS类。
< style>
.VerticalHeaderText {
white-space:pre-wrap;
word-wrap:分词;
width:1px;
//行高需要对字体大小,类型等进行调整
line-height:75%;
}
< / style>
然后,我们需要将标题文本包装在一个具有类 VerticalHeaderText
。为此,我们使用GridViews OnRowDataBound
事件。
protected void GridView1_RowDataBound对象发件人,GridViewRowEventArgs e)
{
if(e.RowType == DataControlRowType.Header)
{
for(int i = 0; i< e.Row .Cells.Count; i ++)
{
e.Row.Cells [i] .Text =< div class = \\VerticalHeaderText \> + e.Row.Cells [i] .Text +< / div>;
$ b $ / code>
在VB中
pre $ Protected Sub GridView1_RowDataBound(ByVal sender As Object,ByVal e As GridViewRowEventArgs)
If(e.Row.RowType = DataControlRowType.Header)然后
Dim i As Integer = 0
Do While(i< e.Row.Cells.Count)
e.Row.Cells(i).Text =(< div class =VerticalHeaderText>_
+(e.Row.Cells(i).Text +< / div>))
i =(i + 1)
Loop
End If
End Sub
I am using grid view to show data but i have many columns with big name.so it contains more screen size.
So please help me with how to get header text vertically so that column doesn't get more screen and i can show my whole grid in same page without scrolling.
I am using visual studio 2005 with vb.net
Any help will be appreciated.
This will work. Although I have to say it looks ugly AF if all the header texts are displayed vertically.
First we need a CSS class.
<style>
.VerticalHeaderText {
white-space: pre-wrap;
word-wrap: break-word;
width: 1px;
//line-height needs some tweaking for font size, type etc
line-height: 75%;
}
</style>
Then we need to wrap the header texts in a container that has the class VerticalHeaderText
. For this we use the GridViews OnRowDataBound
event.
protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.Header)
{
for (int i = 0; i < e.Row.Cells.Count; i++)
{
e.Row.Cells[i].Text = "<div class=\"VerticalHeaderText\">" + e.Row.Cells[i].Text + "</div>";
}
}
}
In VB
Protected Sub GridView1_RowDataBound(ByVal sender As Object, ByVal e As GridViewRowEventArgs)
If (e.Row.RowType = DataControlRowType.Header) Then
Dim i As Integer = 0
Do While (i < e.Row.Cells.Count)
e.Row.Cells(i).Text = ("<div class=""VerticalHeaderText"">" _
+ (e.Row.Cells(i).Text + "</div>"))
i = (i + 1)
Loop
End If
End Sub
这篇关于如何垂直获取GridView标题文本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!