C# – Convert Gridview column from ID to String in ItemTemplate


I currently have a Gridview that displays

TypeID , Name , Description.

I would like to display the actual type name instead of the TypeID in the gridview. I created this function that takes in the ID and returns the Name but I am having trouble using it. There are 15-20 different types so How do I convert the TypeID to a Type Name so that it is displayed when the Gridview is rendered.

protected string GetGenericTypeByID(int genericTypeID)
            string genericTypeName;

            GenericType.Generic_TypeDataTable genericTypeNameDS = new GenericType.Generic_TypeDataTable();
            genericTypeNameDS = GenericBO.Get_GenericTypeByID(genericTypeID);

            genericTypeName = genericTypeNameDS[0]["Generic_Type_Name"].ToString();

            return genericTypeName;


I thought I would be able to use the function in the ItemTemplate but it seems to be harder that I thought

                    <asp:Label ID="Label1" runat="server" Text='<%# Bind("GetGenericTypeByID("Generic_Type_ID")")%>'></asp:Label>

Thanks to Everyone who helped me solve this problem.
I ended up using the method below and it works perfectly.
GetGenericTypeByID( Convert.ToInt32(Eval("Generic_Type_ID")))

Best Solution

You've got the 'bind/eval' and method call inside out.
See Using Method inside a DataGrid or GridView TemplateField

<asp:TemplateField HeaderText=”Name”>
    <a href='<%# FormatUrl(Eval(”email1″).ToString())%>'><%# Eval(”fname”) %>,&nbsp;<%# Eval(”lname”) %></a>

With the 'FormatUrl' function being:

public string FormatUrl(string email)
    return “mailto:” + email;