how - specify length in eval?

  • Thread starter David Bartosik - MS MVP
  • 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?
 
K

Kevin Spencer

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.
 
J

Jos

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")) %>
 
A

Alex Papadimoulis

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
 
Joined
Jul 9, 2007
Messages
1
Reaction score
0
Here's a different way to solve the same prob:

<%# LEFT(DataBinder.Eval(Container.DataItem, "Print_name"),12) %>

>Dave
 

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,769
Messages
2,569,580
Members
45,054
Latest member
TrimKetoBoost

Latest Threads

Top