我正在处理一个asp网络表单页面。我动态填充网格视图的列和行,并使用rowDataBound事件获取每一行和每列的总和。 它工作正常,除非该列的名称类似于"EN.德萨罗罗"。如果 Databinder.eval 在列名中包含".",则它似乎不起作用。还有其他方法可以获取值吗?或者以其他方式使用 databinder.eval?这是我的代码:
private int[] totales = new int[100];
protected void grdTecnicos_RowDataBound(object sender, GridViewRowEventArgs e)
{
List<diccListaString> estados = getEstadosAbiertos();
try
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
for (int i = 0; i < estados.Count() + 2; i++)
{
BoundField field = (BoundField)((DataControlFieldCell)e.Row.Cells[i]).ContainingField;
if (field.HeaderText == "TOTAL")
{
int ac = totales[i - 1];
int n = Convert.ToInt32(DataBinder.Eval(e.Row.DataItem, "TOTAL"));
int t = ac + n;
totales[i - 1] = t;
}
else if (i < estados.Count())
{
int ac = totales[i];
int n = Convert.ToInt32(DataBinder.Eval(e.Row.DataItem, estados[i].Descripcion));// here is the problem
int t = ac + n;
totales[i] = t;
}
}
}
else if (e.Row.RowType == DataControlRowType.Footer)
{
for (int i = 0; i <= estados.Count() + 1; i++)
{
if (i == 0)
e.Row.Cells[0].Text = "TOTAL:";
else
e.Row.Cells[i].Text = totales[i - 1].ToString();
}
}
}
catch (Exception err)
{
mostrar_error(err);
}
}
试试
<%# DataBinder.GetPropertyValue(Container.DataItem, "EN.DESARROLLO") %>
或
<%# ((System.Data.DataRowView)Container.DataItem)["EN.DESARROLLO"] %>