Wednesday, March 28, 2012

Substitute Values in Column in Gridview

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:GridViewI 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

"Wayne Wengert" <wayneSKIPSPAM@.wengert.org> wrote in message
news:ut%232Q9SRGHA.4696@.tk2msftngp13.phx.gbl...
>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>

0 comments:

Post a Comment