Long string ruining formatting

C

Cathie Hagen

Hi All,

I have a long string with no whitespace or break character and it is ruining
the formatting of my datagrid. How can I get the text to wrap whether or
not their are break characters in the string?

Thanks in advance
Cathie
 
K

Ken Cox [Microsoft MVP]

Hi Cathie,

It looks like you'll have to add your own line breaks. Here's some sample
code that uses the ItemDataBound event to check for the length of the text
in the first cell. If it is greater than 20 characters, it loops through the
string and inserts a break (<br>) every 20 characters.

Private Sub DataGrid1_ItemDataBound _
(ByVal sender As Object, ByVal e As _
System.Web.UI.WebControls.DataGridItemEventArgs) _
Handles DataGrid1.ItemDataBound
Dim strAllText As String
Dim strNewText As String = ""
Dim intPos As Integer = 1
If Len(e.Item.Cells(0).Text) > 20 Then
strAllText = e.Item.Cells(0).Text
While intPos < Len(e.Item.Cells(0).Text)
strNewText = strNewText & _
Mid(strAllText, intPos, 20) & "<br>"
intPos = intPos + 20
End While
e.Item.Cells(0).Text = strNewText
End If
End Sub

Does this help?

Ken
Microsoft MVP [ASP.NET]
Toronto
 
C

Cathie Hagen

Thanks
It seems to be working now

Cathie

Ken Cox said:
Hi Cathie,

It looks like you'll have to add your own line breaks. Here's some sample
code that uses the ItemDataBound event to check for the length of the text
in the first cell. If it is greater than 20 characters, it loops through the
string and inserts a break (<br>) every 20 characters.

Private Sub DataGrid1_ItemDataBound _
(ByVal sender As Object, ByVal e As _
System.Web.UI.WebControls.DataGridItemEventArgs) _
Handles DataGrid1.ItemDataBound
Dim strAllText As String
Dim strNewText As String = ""
Dim intPos As Integer = 1
If Len(e.Item.Cells(0).Text) > 20 Then
strAllText = e.Item.Cells(0).Text
While intPos < Len(e.Item.Cells(0).Text)
strNewText = strNewText & _
Mid(strAllText, intPos, 20) & "<br>"
intPos = intPos + 20
End While
e.Item.Cells(0).Text = strNewText
End If
End Sub

Does this help?

Ken
Microsoft MVP [ASP.NET]
Toronto

Cathie Hagen said:
Hi All,

I have a long string with no whitespace or break character and it is
ruining
the formatting of my datagrid. How can I get the text to wrap whether or
not their are break characters in the string?

Thanks in advance
Cathie
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,776
Messages
2,569,603
Members
45,189
Latest member
CryptoTaxSoftware

Latest Threads

Top