views:

223

answers:

1

I'm a total asp.net newbie just fixing a bug in some code.

I want a hidden field that displays the integer representation of a enum.

Currently the following line displays the "Text" / human readable version of the enum.

<asp:Label ID="lblNoteType" runat="server" Text='<%# Bind("NoteType") %>'></asp:Label>

What do I need to do to the "Bind("NoteType")" so that it displays the int representation instead of the verbal?

Thanks

+2  A: 

You should be able to just do:

<%# ((int)(Eval("NoteType"))).ToString() %>

You should be able to cast it directly to an int from the Eval with no need to cast to your enumeration as an intermediate.

I would also suggest not using a label as it includes funcitonality for formatting which is obviously not needed. You could just use a Literal instead and it will maintain all the ViewState for the postbacks you require with none of the Label's formatting overhead.

Kelsey