Reputation: 1108
I need to know how can I use a class to get a string and add it to a label inside an itemtemplate in agridview...
I previously posted this question: Add text from c# code to a gridview label
I got an answer where I noticed I get the string from a class in a cs file... to be more specific, here's my class:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
namespace ClientesPagos
{
public class Funciones
{
public static string GetFormatoMoneda(decimal decCantidad)
{
DataRow dr = ConexionBD.GetInstanciaConexionBD().GetTipoDeMonedaPrincipal((int)HttpContext.Current.Session["Grupo"]);
return dr["Signo"] + Math.Round(decCantidad, 2).ToString("C").Substring(1) + " " + dr["Abreviatura"];
}
}
}
from one of the suggestions, I tried to use this:
Text='<%#Funciones.GetFormatoMoneda(Eval("Total"))%>'
Did not work...
then I tried something that I don't want to do, but just for testing I tried it. My gridview is in a file called Ventas.aspx... so I added that same class on Ventas.aspx.cs and then I switch the text to:
Text='<%#GetFormatoMoneda(Eval("Total"))%>'
also, I tried switching in GetFormatoMoneda(decimal decCantidad) to GetFormatoMoneda(object objCantidad), with no success at all...
Do you know a way to fix this? or if you could provide a different answer on the other question on the link above?
Upvotes: 0
Views: 1119
Reputation: 366
It should be:
Text='<%# Eval(Funciones.GetFormatoMoneda(1.0))%>'
Just replace the 1.0
I have written inside the function call GetFormatoMoneda
.
Upvotes: 1
Reputation: 407
You can use gridview.rowdatabound event to manipulate grid row in the code behind.
Upvotes: 2