Displaying enum values with DataGrid Web Control

  • Thread starter Maksim Izboridin
  • Start date
M

Maksim Izboridin

Hello,

In my ASP.NET application I have to display the contents
of a table in a DataGrid web control. The table is stored
in a DataSet (I get it from an external application). One
column of the table contains a set of integer values,
each one representing an enumerated value. What should I
do in order to display a string corresponding to the
integer instead of displaying the integer values for this
column in my DataGrid?

Thank you,
Maxim
 
L

Lostinet.Web Support

<TemplateColumn>
<ItemTemplate><% # CodeBeindeMethod_GetIntName( Container.DataItem )
%></ItemTemplate>
</TemplateColumn>
 
J

Jeffrey Tan[MSFT]

Hi Maksim,

Thanks for posting in this group.
You can use Enum.GetName method to get this int value's string
representation, so you can do like this:
<asp:TemplateColumn SortExpression="enum" HeaderText="Enum">
<ItemTemplate>
<%# Getenumstring(Container.DataItem) %>
</ItemTemplate>
</asp:TemplateColumn>

//code behind:
public enum testenum
{
yes, no
};

public string Getenumstring(object item)
{
DataRowView row=(DataRowView)item;
return Enum.GetName(typeof(testenum), row["enum"]);
}

Hope this helps,

Best regards,
Jeffrey Tan
Microsoft Online Partner Support
Get Secure! - www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.
 

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,582
Members
45,069
Latest member
SimplyleanKetoReviews

Latest Threads

Top