is this a lot

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

hey all,

i'm using the DataGrid1_ItemDataBound event like this:

If e.Item.ItemType = ListItemType.Item _
Or e.Item.ItemType = ListItemType.AlternatingItem _
Or e.Item.ItemType = ListItemType.SelectedItem Then

Dim sValue As String
sValue = e.Item.DataItem("PTPROBM")
If sValue.Length > 20 Then
e.Item.Cells(1).Text = sValue.Substring(0, 50)
End If

Are there any other ways to do this more gracefully? or less code? just
wondering?

thanks,
rodchar
 
here a cute little function we wrote to cutoff extra long descriptions for
the purposes of dropdownlist or grids.
<Description("Truncates a given string to a specified length and adds
ellipsis to the end if necessary")> _
Public Function AddEllipsis(ByVal inputstr As String, ByVal outputlen As
Integer) As String

Dim miPosition As Integer
If Len(inputstr) <= outputlen Then
AddEllipsis = inputstr
Else
miPosition = InStrRev(inputstr, " ", outputlen, 1)
AddEllipsis = Left(inputstr, miPosition) & "..."
End If
End Function



in your case you could get rid of almost all the code in your itemdatabound
event and use:

e.item.cells(1).text = addellipsis(e.Item.DataItem("PTPROBM"),20)

you might want to consider using a label instead of changing the cell text
directly. that way you can better control fonts or colors without having to
write html tags?

later,

Kirk
 
here a cute little function we wrote to cutoff extra long descriptions
for
the purposes of dropdownlist or grids.
<Description("Truncates a given string to a specified length and adds
ellipsis to the end if necessary")> _
Public Function AddEllipsis(ByVal inputstr As String, ByVal outputlen As
Integer) As String

Dim miPosition As Integer
If Len(inputstr) <= outputlen Then
AddEllipsis = inputstr
Else
miPosition = InStrRev(inputstr, " ", outputlen, 1)
AddEllipsis = Left(inputstr, miPosition) & "..."
End If
End Function



in your case you could get rid of almost all the code in your
itemdatabound
event and use:

e.item.cells(1).text = addellipsis(e.Item.DataItem("PTPROBM"),20)

you might want to consider using a label instead of changing the cell
text
directly. that way you can better control fonts or colors without having
to
write html tags?

later,

Kirk

If you're using data from a database, and are only using this field here,
I might recommend trimming there (in the SQL) as it should be faster than
doing it in code (not to mention less data being piped across).
 
thanks everyone, this helped.

Craig Deelsnyder said:
If you're using data from a database, and are only using this field here,
I might recommend trimming there (in the SQL) as it should be faster than
doing it in code (not to mention less data being piped across).
 

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

Back
Top