Re: Datagrid and switch

From: Karl (none)
Date: 08/19/04


Date: Thu, 19 Aug 2004 13:29:31 -0400

The easiest way is to call on a function

<span class="Normal"><%#
ConvertFieldType((int)(DataBinder.Eval(Container.DataItem, "FieldType"))
%></span>

and then just define a function
public string ConvertFieldType(int fieldTypeId){
   switch(fieldTypeId){
     case 1:
       return "cars";
    ....
   }
}

The function can either be in your code behind or in a <Script
runat="server"> block

"Arjen" <boah123@hotmail.com> wrote in message
news:cg2m4k$4mu$1@news5.tilbu1.nb.home.nl...
> Hello,
>
> My datagrid shows some values out of a database.
> For example 1,1,2,3,2,3,4,1.
>
> Now these numbers are not realy nice... so I want to convert the numbers.
> If it is a 1 it must show cars.
> If it is a 2 is must show bikes.
>
> How can I convert this in C#?
>
> I have now this. (But doesn't works)
> Can somebody help me?
> Thanks!
>
> -----------
>
> <ItemTemplate>
> <span class="Normal">
> <%
> switch(DataBinder.Eval(Container.DataItem,"FieldType")) {
>
> case 0:
> break;
> case 1:
> break;
> case 2:
> break;
> case 3:
> break;
> case 4:
> break;
> case 5:
> break;
> }
> %>
> </span>
> </ItemTemplate>
>
>



Relevant Pages

  • Re: Serialization of a custom collection
    ... it seems I'll have to create a "wrapper" ... public class CarCollection: List ... public string Model; ... CarCollection cars = GetCars; ...
    (microsoft.public.dotnet.languages.csharp)
  • RE: web service error - urgent
    ... What about this instead (return an array of Cars): ... Object o, XmlSerializerNamespaces namespaces, String encodingStyle, String id) ... public string make; ...
    (microsoft.public.dotnet.framework.webservices)
  • RE: web service error - urgent
    ... What is "ports" anyway? ... What about this instead (return an array of Cars): ... Object o, XmlSerializerNamespaces namespaces, String encodingStyle, String id) ... public string make; ...
    (microsoft.public.dotnet.framework.webservices)
  • How do I create a class item with properties?
    ... A class called Cars ... public string Mazda; ...
    (microsoft.public.dotnet.general)