Bind/Eval part of a column

  • Thread starter Thread starter David C
  • Start date Start date
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>
 
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.
 
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.
 
Back
Top