[英]Setting label text in DataBinding in a GridView (ASP.NET/C#)
[英]ASP.NET how to add text to label in gridview using a class in C# code?
我需要知道如何使用類來獲取字符串並將其添加到agridview中itemtemplate內的標簽中...
我之前曾發布過以下問題: 將C#代碼中的文本添加到gridview標簽中
我得到一個答案,我注意到我從cs文件中的類中獲得了字符串……更具體地說,這是我的類:
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"];
}
}
}
從建議之一,我試圖使用此:
Text='<%#Funciones.GetFormatoMoneda(Eval("Total"))%>'
不工作...
然后我嘗試了一些我不想做的事情,但是只是為了測試,我嘗試了一下。 我的gridview在一個名為Ventas.aspx的文件中...因此我在Ventas.aspx.cs上添加了相同的類,然后將文本切換為:
Text='<%#GetFormatoMoneda(Eval("Total"))%>'
另外,我嘗試將GetFormatoMoneda(十進制decCantidad)切換到GetFormatoMoneda(對象objCantidad),但沒有成功...
您知道解決此問題的方法嗎? 或者您是否可以在上面的鏈接中對其他問題提供不同的答案?
您可以使用gridview.rowdatabound事件在后面的代碼中操作網格行。
它應該是:
Text='<%# Eval(Funciones.GetFormatoMoneda(1.0))%>'
只需替換我在函數調用GetFormatoMoneda
編寫的1.0
。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.