0

我继承了一段代码(如下)。从它填充的列表项中,我不想填充我知道“变体”是#AAB 的行。

有没有办法以相同的方式填充表格,但忽略带有变体 AAB 的行?

public void BuildList()
{
    DataTable variants = Common.GetAllVariantsFromDB(modelCode);
    variantsList.InnerHtml += "<span id=\"variant\">" + Common.GetVariantInfo(variant)[0] + "</span>";
    variantsList.InnerHtml += "<ul id=\"variantsList\">";
    for (int i = 0; i < variants.Rows.Count; i++)
    {
        variantsList.InnerHtml += "<li><a href=\"#" + variants.Rows[i]["Variant"].ToString() + "\">" + variants.Rows[i]["EngineSize"].ToString()</a></li>";
    }
    variantsList.InnerHtml += "</ul>";
}
4

2 回答 2

2

通过添加如下条件将过滤项目

 for (int i = 0; i < variants.Rows.Count; i++)
        {
          if(variants.Rows[i]["Variant"].ToString()!="#AAB")
            variantsList.InnerHtml += "<li><a href=\"#" + variants.Rows[i]["Variant"].ToString() + "\">" + variants.Rows[i]["EngineSize"].ToString()</a></li>";
        }
于 2013-07-09T08:40:34.167 回答
0
public void BuildList()
{
    DataTable variants = Common.GetAllVariantsFromDB(modelCode);
    variantsList.InnerHtml += "<span id=\"variant\">" + Common.GetVariantInfo(variant)[0] + "</span>";
    variantsList.InnerHtml += "<ul id=\"variantsList\">";
    for (int i = 0; i < variants.Rows.Count; i++)
    {
        if (variants.Rows[i]["Variant"].ToString() != "GJ1")
        {
            variantsList.InnerHtml += "<li><a href=\"#" + variants.Rows[i]["Variant"].ToString() + "\">" + variants.Rows[i]["EngineSize"].ToString()</a></li>";
        }
    }
    variantsList.InnerHtml += "</ul>";
}
于 2013-07-09T08:49:38.847 回答