我有这个代码使用LINQ来填充DropDownList:
var userCategories = DataAccessLayer.Context.Categories
.Where(c => c.UserName == HttpContext.Current.User.Identity.Name)
.Select(c => new { c.ID, c.Category })
.OrderBy(c => c.Category);
CategoryDropDownList.DataSource = userCategories;
CategoryDropDownList.DataValueField = "ID";
CategoryDropDownList.DataTextField = "Category";
CategoryDropDownList.DataBind();
我将Server.HtmlDecode放在哪个类别?
答案 0 :(得分:1)
首先,你需要HtmlEncode,而不是HtmlDecode。这是一个例子:
foreach (var category in userCategories)
{
CategoryDropDownList.Items.Add(new ListItem(Server.HtmlEncode(category.Category), category.ID.ToString()));
}