GridView的列的数据分行显示

今天,在将数据绑定到GridView时,发现其中一个列的数据特别的长,占去了页面大部分的宽度,如下图,

怎样使这列的数据像旁边的两列一样显示呢?

首先,设置当前列的Item_style中的Wrap 属性为True。一般,这样就可以了。如果数据格式是像上图显示的一样,那就麻烦了。 因为,AutoWrap 只会在遇到空格才会换行。

在我的项目中,因为这行数据是在绑定后插入的,所以解决起来比较容易。

Protected Sub FillTest()
Dim cs As String = ConfigurationManager.ConnectionStrings("TestConnectionString").ConnectionString.ToString
Dim cn As New SqlClient.SqlConnection(cs)
Dim cmdText As String = "SELECT qr.character1,qr.character2 FROM table1 qr, table2 qp Where qr.plan_id = qp.plan_id"
Dim cmd As New SqlClient.SqlCommand(cmdText, cn)
Dim charSeparators() As Char = {";"c}
Dim da As New SqlClient.SqlDataAdapter(cmd)
cmd.CommandTimeout
= 600
Dim hstblSalesOffice As New Hashtable

Dim salesOffices, hshKey, hshValue, LBPPersonName As String
Dim ds As New Data.DataSet
Dim drChar As DataRow
da.Fill(ds)
For Each drChar In ds.Tables(0).Rows
LBPPersonName
= drChar("character1")
salesOffices
= drChar("character2")
For Each hshKey In salesOffices.Split(charSeparators, StringSplitOptions.None)
If hstblSalesOffice.ContainsKey(hshKey) Then
If (txtCSPerson.Text.Trim() = String.Empty) Then
hshValue
= hstblSalesOffice.Item(hshKey)
'Column wrap will work only when there are some spaces between strings
hshValue = hshValue & " / " & LBPPersonName
hstblSalesOffice.Item(hshKey)
= hshValue
Else
hshValue
= txtCSPerson.Text.ToString
hstblSalesOffice.Item(hshKey)
= hshValue
End If
Else
hstblSalesOffice.Add(hshKey, LBPPersonName)
End If
Next
Next
Session(
"CSPerson") = hstblSalesOffice
ds.Dispose() : da.Dispose() : cmd.Dispose() : cn.Dispose()
End Sub
posted @ 2011-03-09 18:09  scogee  阅读(1363)  评论(0编辑  收藏  举报