Reputation: 219
I have a GridView and there is a column named status. On displaying the value in this column i have used itemtemplate. Currently, it shows the result of value of EVAL but i want to show text based on the values of eval.
<asp:GridView ID="GridView1" runat="server"/>
<Columns>
<asp:TemplateField HeaderText="Status">
<ItemTemplate>
<%# Eval("ICB_SUBS_STATUS")%>
</ItemTemplate>
<EditItemTemplate>
<asp:DropDownList ID="DropDownList1" runat="server" SelectedValue='<%# Eval("ICB_SUBS_STATUS")%>'>
<asp:ListItem Value = '0'>Applet not installed.</asp:ListItem>
<asp:ListItem Value = '1'>ICB Service not activated. Applet installed.</asp:ListItem>
<asp:ListItem Value = '2'>Active ICB Subscriber. Applet installed.</asp:ListItem>
<asp:ListItem Value = '3'>Subscriber deactivated ICB. Applet installed.</asp:ListItem>
</asp:DropDownList>
</EditItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
As in above case, on edit template the dropdownlist text is shown based on value. Also, i want to show text on normal display of gridview. Any idea and suggestion will be very helpful!! Sorry, if my english is poor!
Upvotes: 2
Views: 4124
Reputation: 190
Create a method in your code behind that translates this value to a human readable string.
protected string Translate_ICB_SUBS_STATUS(int ICB_SUBS_STATUS)
{
switch (ICB_SUBS_STATUS)
{
case 0:
return "Applet not installed.";
case 1:
return "ICB Service not activated. Applet installed.";
...
}
}
Then in your binding, use the method
<ItemTemplate>
<%# this.Translate_ICB_SUBS_STATUS(Int32.Parse(Container.DataItem("ICB_SUBS_STATUS").ToString())) %>
</ItemTemplate>
Upvotes: 5