Bind/Eval part of a column

D

David C

I have a Label in a bound GridView column that I want to display all but the
1st character. For example, one of the MealCodeSort columns might contain a
value of '1AM Meal' and I want to display just 'AM Meal'. Below is my Label
that I currently have. Thanks.

David

<asp:Label ID="LblMealCode" runat="server" Text='<%# Eval("MealCodeSort")
%>' Font-Bold="true"></asp:Label>
 
D

daveh551

I have a Label in a bound GridView column that I want to display all but the
1st character.  For example, one of the MealCodeSort columns might contain a
value of '1AM Meal' and I want to display just 'AM Meal'.  Below is my Label
that I currently have.  Thanks.

David

<asp:Label ID="LblMealCode" runat="server" Text='<%# Eval("MealCodeSort")
%>' Font-Bold="true"></asp:Label>

I'm a little shaky on this, but, at least to my understanding, you
should be able to put any legitimate statement between the <% and %>.
That means you should be able to say something like '<%# ((String) Eval
("MealCodeSort")).Substring(1)%>

Or, if that doesn't work, you can define a simple function in your
code-behind file that does that, and call it:

<%# mySubstringFunc(Eval("MealCodeSort"))%>
I'm sure that works, because I've done something similar.

Alternatively, you could define another column in you database view
(if you have that access) that is the MealCodeSort with the first
character stripped, and display that instead.
 
D

David C

That worked perfect! Thanks.

David
I have a Label in a bound GridView column that I want to display all but
the
1st character. For example, one of the MealCodeSort columns might contain
a
value of '1AM Meal' and I want to display just 'AM Meal'. Below is my
Label
that I currently have. Thanks.

David

<asp:Label ID="LblMealCode" runat="server" Text='<%# Eval("MealCodeSort")
%>' Font-Bold="true"></asp:Label>

I'm a little shaky on this, but, at least to my understanding, you
should be able to put any legitimate statement between the <% and %>.
That means you should be able to say something like '<%# ((String) Eval
("MealCodeSort")).Substring(1)%>

Or, if that doesn't work, you can define a simple function in your
code-behind file that does that, and call it:

<%# mySubstringFunc(Eval("MealCodeSort"))%>
I'm sure that works, because I've done something similar.

Alternatively, you could define another column in you database view
(if you have that access) that is the MealCodeSort with the first
character stripped, and display that instead.
 

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

Forum statistics

Threads
473,773
Messages
2,569,594
Members
45,119
Latest member
IrmaNorcro
Top