2013-07-09 52 views
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>"; 
} 

回答

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>"; 
     } 
+0

許多感謝,對REF(你們大家)。完成的代碼將在下面發佈。 – wilsonlego

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>"; 
}