How to set a condition in the grid snap field?

here is my code -

<asp:BoundField DataField="DayOfTheWeek" HeaderText="Day" ItemStyle-CssClass="Itemstyle"/>

from my collection object I get DayOfTheWeek as 1,2 ... 7. 1 on Monday, 2 on Tuesday. Where should I place the condition so that in grid mode it displays the name of the day, and not the corresponding code.

+3
source share
1 answer

You can use Enum.Parse in the DayOfWeek enumeration to return the text of the day in the TemplateField:

<asp:TemplateField HeaderText="Day" ItemStyle-CssClass="Itemstyle">
    <ItemTemplate>
        <%# Enum.Parse(typeof(DayOfWeek), DataBinder.Eval(Container.DataItem, "DayOfTheWeek").ToString()) %>
    </ItemTemplate>
</asp:TemplateField>
+2
source

Source: https://habr.com/ru/post/1776440/


All Articles