【问题标题】:How to get GridView Header Text vertically如何垂直获取GridView标题文本
【发布时间】:2016-11-04 05:05:13
【问题描述】:

我正在使用网格视图来显示数据,但我有很多大名称的列。所以它包含更多的屏幕尺寸。

所以请帮助我如何垂直获取标题文本,以便该列不会获得更多屏幕,并且我可以在同一页面中显示我的整个网格而无需滚动。

我正在使用带有 vb.net 的 Visual Studio 2005

任何帮助将不胜感激。

【问题讨论】:

  • 您是否尝试过
    为标题文本的每个字母?如果可能,请发布您的网格绑定代码。

标签: asp.net vb.net gridview


【解决方案1】:

这会奏效。虽然我不得不说如果所有标题文本都垂直显示,它看起来很难看。

首先我们需要一个 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

【讨论】:

  • 我知道这是一个老答案,但我很好奇你为什么在 C# 中使用 for 循环,而在 VB 中使用 While 循环?
  • @Slugsie,没有理由。我已经通过在线代码翻译器将 C# 代码放入,结果就是这样。
【解决方案2】:
   /*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";

【讨论】:

  • 您能解释一下您的方法吗?
猜你喜欢
  • 2017-04-13
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2017-11-02
  • 1970-01-01
  • 2015-01-07
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多