li的选项价值

时间:2012-06-12 12:35:22

标签: c# asp.net html-lists

如何将此行代码转换为例如<li>DE</li>

optionlist.Append("<option value=\"" +
                  DB.RSField(rs, "Name") +
                  "\" " +
                  CommonLogic.IIF(currentLocaleSetting == DB.RSField(rs, "Name"), " selected ", String.Empty) +
                  ">" +
                  DB.RSField(rs, "Description") +
                  "</option>");

我也试过这个:

optionlist.Append("<li>" + "a href=" + 
"/setlocale.aspx?returnURL=Default.aspx&localesetting=" + DB.RSField(rs, "Name") +
 "</a>" + CommonLogic.IIF(currentLocaleSetting == DB.RSField(rs, "Name"), "", String.Empty) + "" + DB.RSField(rs, "Description") + "</li>");

但这会产生以下错误:

a href=/setlocale.aspx?returnURL=Default.aspx&localesetting=de-DEDeutsch

1 个答案:

答案 0 :(得分:2)

代码应如下所示,以便生成列表项:

optionlist.Append("<ul>");

//loop start here...
optionlist.AppendFormat("<li>{0}</li>", DB.RSField(rs, "Name"));
//loop ends here...

optionlist.Append("</ul>");

这会“失去”描述,所以也要添加它:

optionlist.Append("<ul>");

//loop start here...
optionlist.AppendFormat("<li>{0} <a href=\"/setlocale.aspx?returnURL=Default.aspx&localesetting={0}\">{1}</a></li>", DB.RSField(rs, "Name"), DB.RSField(rs, "Description"));
//loop ends here...

optionlist.Append("</ul>");

以上将显示每个名称旁边的说明。