GridView的列的数据分行显示
时间:2011-03-09 来源:Dannier
今天,在将数据绑定到GridView时,发现其中一个列的数据特别的长,占去了页面大部分的宽度,如下图,
怎样使这列的数据像旁边的两列一样显示呢?
首先,设置当前列的Item_style中的Wrap 属性为True。一般,这样就可以了。如果数据格式是像上图显示的一样,那就麻烦了。 因为,AutoWrap 只会在遇到空格才会换行。
在我的项目中,因为这行数据是在绑定后插入的,所以解决起来比较容易。
Protected Sub FillCSPerson()
Dim cs As String = ConfigurationManager.ConnectionStrings("ValvesTestConnectionString").ConnectionString.ToString
Dim cn As New SqlClient.SqlConnection(cs)
Dim cmdText As String = "SELECT qr.character1,qr.character2 FROM qa_results qr, qa_plans qp Where qp.NAME LIKE 'USER SALES OFC GROUPING VLVS' AND 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
相关阅读 更多 +