Change GridView data before display

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?
 
I

Ignacio Machin \( .NET/ C# MVP \)

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.";
}
}
 

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

Top