【发布时间】:2016-11-04 05:05:13
【问题描述】:
我正在使用网格视图来显示数据,但我有很多大名称的列。所以它包含更多的屏幕尺寸。
所以请帮助我如何垂直获取标题文本,以便该列不会获得更多屏幕,并且我可以在同一页面中显示我的整个网格而无需滚动。
我正在使用带有 vb.net 的 Visual Studio 2005
任何帮助将不胜感激。
【问题讨论】:
-
您是否尝试过
为标题文本的每个字母?如果可能,请发布您的网格绑定代码。
我正在使用网格视图来显示数据,但我有很多大名称的列。所以它包含更多的屏幕尺寸。
所以请帮助我如何垂直获取标题文本,以便该列不会获得更多屏幕,并且我可以在同一页面中显示我的整个网格而无需滚动。
我正在使用带有 vb.net 的 Visual Studio 2005
任何帮助将不胜感激。
【问题讨论】:
这会奏效。虽然我不得不说如果所有标题文本都垂直显示,它看起来很难看。
首先我们需要一个 CSS 类。
<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>
然后我们需要将标题文本包装在具有VerticalHeaderText 类的容器中。为此,我们使用 GridViews OnRowDataBound 事件。
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>";
}
}
}
在 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
【讨论】:
/*Use the css on page tittle*/
<style>
.verticaltext
{
writing-mode: tb-rl;
filter: flipv fliph;
}
</style>
/*Call this code on gridview_Rowdatabound*/
GridViewRow header = gv.HeaderRow;
header.Cells[1].CssClass = "verticaltext";
【讨论】: