how - specify length in eval?

  • Thread starter Thread starter David Bartosik - MS MVP
  • Start date Start date
D

David Bartosik - MS MVP

If I have...

<TD><%# DataBinder.Eval(Container.DataItem, "Print_name")
%></TD>

and I want to display only the first 12 characters of the "Print_name" data
field, how is that done?
 
Create a Property in the Container that returns the first 12 characters of
the "Print_Name" data, and refer to that property.

--
HTH,
Kevin Spencer
..Net Developer
Microsoft MVP
Big things are made up
of lots of little things.
 
David said:
If I have...

<TD><%# DataBinder.Eval(Container.DataItem, "Print_name")
%></TD>

and I want to display only the first 12 characters of the
"Print_name" data field, how is that done?

Write a function (this is for VB):

Function Truncate(o As Object) As String
Return Left(o.ToString(),12)
End Function

Then, use this binding syntax:

<%# Truncate(DataBinder.Eval(Container.DataItem, "Print_name")) %>
 
Hi David,

Helper functions are great, but for such a simple thing, I use the ever
helpful latebinding:

<%# Container.DataItem.Print_name.substring(0,12) %>

it'll work assuming Print_name can be converted to a string, and length is
= 12 -- and if you cant be certain of those, then add logic to the <%#
expression, or resort to the helper function.

-- Alex Papadimoulis
 
Back
Top