I have the following code:
Dim db As New linqclassesDataContext Dim categories = (From c In db.faq_cats) NewFaqDropDownCategory.DataSource = categories NewFaqDropDownCategory.DataTextField = "category" NewFaqDropDownCategory.DataValueField = "category_id" If Not Page.IsPostBack Then NewFaqDropDownCategory.DataBind() End If Unset(categories) Unset(db)
One of the items under the column "category" has & in the title, and that shows up in the dropdownlist as such. Is there someway to make the list display "&" instead?
One Solution
I figured I could use the .Replace() function to do this, and I accidentally found out how:
For Each c In categories If c.category.Contains("&") Then c.category = c.category.Replace("&", "&") End If Next
I could expand this in the future to process other values as well.
If there are other HTML encoded characters in there as well you could use
HttpUtility.HtmlDecode(c.category). This would prevent your replace and ensure that any characters are properly decoded.I don’t know if this is exact VB linq anonymous object syntax, but I tried.
Then bind your DDL to that datasource.
You could also just use .Replace if you only need
&