2016-11-04 48 views
0

我正在使用網格視圖來顯示數據,但我有很多與大name.so它包含更多的屏幕大小的列。如何垂直獲取GridView標題文本

所以,請幫助我如何垂直獲取標題文本,以便列不會獲得更多的屏幕,我可以在不滾動的情況下在同一頁面顯示我的整個網格。

我使用visual studio 2005與vb.net

任何幫助將不勝感激。

+0

你試過
每個字母爲標題的文本?如果可能,請發佈您的網格綁定代碼。 –

回答

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 
+0

謝謝你。它爲我工作。 –