How to put condition in grid view bound field?
-
27-09-2019 - |
Question
here my code-
<asp:BoundField DataField="DayOfTheWeek" HeaderText="Day" ItemStyle-CssClass="Itemstyle"/>
from my collection entity I am getting DayOfTheWeek like 1,2...7. 1 for monday , 2 for tuesday like that. Where should I place condition so that in grid view it would display day name rather than corresponding code.
Solution
You can use Enum.Parse on the DayOfWeek enum to get the day text back in a TemplateField:
<asp:TemplateField HeaderText="Day" ItemStyle-CssClass="Itemstyle">
<ItemTemplate>
<%# Enum.Parse(typeof(DayOfWeek), DataBinder.Eval(Container.DataItem, "DayOfTheWeek").ToString()) %>
</ItemTemplate>
</asp:TemplateField>
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow