如何在String Builder上添加CheckBoxList Item。
CheckBoxList cblItem = new CheckBoxList();
cblItem.ID = "cblItem";
var MainCatGroup = subCatDet.GroupBy(q => q.catCode).Select(q => new { CatName = q.Key, Items = q.ToArray() }).Select(q => new { CatName = q.CatName, Items = q.Items.OrderBy(t => t.catCode).ToArray() }).ToArray();
foreach (var mainCat in MainCatGroup)
{
sb.Append(string.Format("<li><a href=\"javascript:void(0)\">{0}</a>", mainCat.CatName.ToString()));
sb.Append(string.Format("<ul>"));
foreach (var item in mainCat.Items)
{
string Subcat = item.subCat.ToString();
string catCode= item.catCode.ToString();
sb.Append(string.Format("<li>"));
-----> sb.Append(string.Format(cblItem.Items.Add(new ListItem("{0},{1}")), Subcat, catCode)); <----
sb.Append(string.Format("</li>"))
}
litList.Text = sb.ToString();
}
那么,我如何在线下编辑?
sb.Append(string.Format(cblItem.Items.Add(new ListItem("{0},{1}")), Subcat, catCode));
答案 0 :(得分:1)
你可能想要做这样的事情:
cblItem.Items.Add(new ListItem(sb.ToString()), Subcat, catCode);
或更好:
cblItem.Items.Add(new ListItem(string.Format("{0},{1}", Subcat, catCode));
你也不能混合命名对话。不应将Subcat和MainCatGroup局部变量命名为大写字母。
在和你也可以尝试StringFormat.AppendFormat(more details here):
sb.AppendFormat("2) {0}, {1}", var1, var2);