Change GridView data before display

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I am binding a database table to a GridView control. This table has an
enumeration in it. I would like to change the text displayed for each
enumeration value to something that is a little more user friendly. What is
the easiest way to accomplish this? Is it just to loop throught the data
and change it before binding or is there a more elegant solution?
 
Hi,


You can use several tricks, one is to use the ItemBound event and then
change the text depending of the value.

The solution I prefer though is using a TemplateColumn you can define a
method that do the conversion:
<asp:TemplateField HeaderText="Renewal">
<ItemTemplate>
<span>
<%#FormatCorrectly(Eval("RenewalComission"))%>
</span>
</ItemTemplate>


Then int he code behind:
protected string FormatCorrectly( object o)
{
//yours will look like
switch( (YourEnum)o)
{
case .... : return "Your visual rep.";
}
}
 
Back
Top