ppp
ppp

Reputation: 303

How to put condition in grid view bound field?

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.

Upvotes: 3

Views: 1597

Answers (1)

Jeff the Bear
Jeff the Bear

Reputation: 5653

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>

Upvotes: 2

Related Questions