Substitute Values in Column in Gridview

W

Wayne Wengert

I have a Gridview bound to an SQLDataSource (see code below). The value of
the "DayOfWeek" column is actually an integer where 0 = Daily, 1=Sunday,
2=Monday, etc. How can I change what is displayed in the column from values
like 1or 2 to "Sunday", "Monday"?


============== Code =================
<asp:GridView ID="GridView1" runat="server" AllowPaging="True"
AllowSorting="True"

AutoGenerateColumns="False" DataSourceID="SqlDataSource1">

<Columns>

<asp:BoundField DataField="EventName" HeaderText="EventName"
SortExpression="EventName" />

<asp:BoundField DataField="DayOfWeek" HeaderText="DayOfWeek"
SortExpression="DayOfWeek" />

<asp:BoundField DataField="Occurs" HeaderText="Occurs"
SortExpression="Occurs" />

<asp:BoundField DataField="Location" HeaderText="Location"
SortExpression="Location" />

</Columns>

</asp:GridView>
 
W

Wayne Wengert

I finally found an example that I could apply. I created a Select Case
function named GetDayOfWeek to return the string I wanted for each case and
then replaced the Bound Column in the ASP code to:

<asp:TemplateField HeaderText="Day of Week">

<ItemTemplate>

<%#GetDayOfWeek(CInt(Eval("DayOfWeek")))%>

</ItemTemplate>

</asp:TemplateField>



Wayne
 

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,995
Messages
2,570,230
Members
46,816
Latest member
SapanaCarpetStudio

Latest Threads

Top