【发布时间】:2014-01-01 15:05:06
【问题描述】:
我有一个产品数量列表和一个网格视图。网格视图已经绑定到一些数据。但我想在网格视图的第三列显示产品数量列表。这是我如何将数据绑定到网格视图的代码:
gvProduct.DataSource = distSPUItem;
gvProduct.DataBind();
BoundField column = new BoundField();
column = new BoundField();
column.HeaderText = "Unit Quantity";
for (int index = 0; index < productQuantityList.Count; index++)
{
column.DataField = index.ToString();
}
gvProduct.Columns.Add(column);
我需要遍历产品数量列表并在网格视图的第三列显示结果。但是,该列不显示。有什么解决办法吗?
提前致谢。
编辑部分
protected void gvProduct_RowDataBound(Object sender, GridViewRowEventArgs e)
{
int unitQuantity = 0;
if(e.Row.RowType == DataControlRowType.DataRow)
{
for(int index = 0; index < productQuantityList.Count; index++)
{
unitQuantity = productQuantityList[index];
}
Label lblUnitQuantity = (Label)e.Row.FindControl("lblUnitQuantity");
lblUnitQuantity.Text = unitQuantity.ToString();
}
}
【问题讨论】:
-
distSPUItem和productQuantityList的类型是什么? -
distSPUItem 是从一个类 List
distSPUItem = new List (); 中检索的。 productQuantityList 是整数类型。我是否以错误的方式定义新列?