我试图向GridView添加条件语句;但是,它似乎只在第一行工作。使用IF ELSE语句循环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] – oppassum