【发布时间】:2015-07-10 14:09:46
【问题描述】:
我正在尝试向 GridView 添加条件语句;但是,它似乎只在第一行工作。
我有一个 HiddenField,我在其中提取我的折扣值,然后是一个标签 在我返回所述值的地方,只有当该值不是 0.00 时,它才会产生中断。 我假设我可以简单地遍历网格行来完成这个;但是,如前所述,它仅适用于第一行。这是我的代码:
// Number of rows in grid
int rowsCount = grid.Rows.Count;
//Loop through the rows
for (int i = 0; i < rowsCount; i++)
{
Label discountLabel = (Label)(grid.Rows[0].FindControl("discountLabel"));
HiddenField discount = (HiddenField)(grid.Rows[0].FindControl("HiddenField1"));
string discountValue = discount.Value;
if (discountValue == "0.00")
{
discountLabel.Text = "<br />";
}
else
{
discountLabel.Text = "NOW " + (String.Format("{0:c}", discountValue));
}
}
【问题讨论】:
-
将 grid.Rows[0] 更改为 grid.Rows[i]