GridView的列的数据分行显示

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

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

首先,设置当前列的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

转载于:https://www.cnblogs.com/Dannier/archive/2011/03/09/1978609.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值