Ok, so item width won't work as it's pixel based, not character based as Jason states.
you need to handle this on the RowDataBound event for each row in your grid.
this example is in VB, though converting it to C# won't be too hard for you i'm sure.
In your codebehind do something like this - replace "MyGridView" with the name of your grid.
First off, change your bound field to a template field; much easier to control.. and in that template put a Literal
that will hold your text, call this MyLit for this example
Private Sub MyGridView(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewRowEventArgs) Handles MyGridView.RowDataBound
'' only want to deal with Data type rows, and not headers etc
If (e.Row.RowType = DataControlRowType.DataRow) Then
'' get this instance of the object you're binding (assuming object is Assignment)
Dim assignment As Assignment = CType(e.Row.DataItem, Assignment)
'' now get the literal control where you will be putting your text
Dim MyLit as Literal = row.FindControl("MyLit")
'' you can now call a recursive method and insert a line break every 20 chars
MyLit.Text = InsertlineBreak(assignment.TextToSplitUp)
End If
End Sub
Function InsertlineBreak(ByVal original As String) As String
Dim MaxStringLength As Int16 = 20
If original.Length > MaxStringLength Then
Dim indexOfSpace = original.IndexOf(" ", MaxStringLength - 1)
If indexOfSpace <> -1 AndAlso indexOfSpace <> original.Length - 1 Then
Dim firstString As String = original.Substring(0, indexOfSpace)
Dim secondString As String = original.Substring(indexOfSpace)
Return firstString & Chr(10) & InsertlineBreak(secondString)
Else
Return original
End If
Else
Return original
End If
End Function
I haven't tested this code - I have just knocked it up for example, though it will give you an idea on how to proceed. Please don't just copy/paste and then comment that it doesn't work right out of the box. More would need to be know to give an exact working example. :)