ddlCats.DataSource = listOfCats;
ddlCats.DataBind();
If an item contains say, &, it will appear in the ddl as &
How can I stop this? I am using asp.net
ddlCats.DataSource = listOfCats;
ddlCats.DataBind();
If an item contains say, &, it will appear in the ddl as &
How can I stop this? I am using asp.net
im having the same problem here and here is the code for those interested (not a fix but a example of the problem )
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="HtmlEncodeDropDownList.aspx.cs" Inherits="ForumExampleCode_HtmlEncodeDropDownList" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title>HTML Encode Drop Down List Example (english, c# only)</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<h1>HTML Encode Drop Down List Example (english, c# only)</h1>
<asp:dropdownlist id="ddlCountry" runat="server" />
<div>
This is how it should look in the drop down list:<br />
côte d'ivoire<br />
são tomé and príncipe
</div>
</div>
</form>
</body>
</html>
and code behind is here
using System;
using System.Collections.Generic; using System.Data; using System.Linq; using System.Web; using System.Web.UI; using System.Web.UI.WebControls;
public partial class ForumExampleCode_HtmlEncodeDropDownList : System.Web.UI.Page { protected void Page_Load(object sender, EventArgs e) { #region region 1: create a datatable and fill with values
//note: declare objects
DataTable countryTable = new DataTable();
//note: add data columns to datatabl
DataColumn newColumn1 = new DataColumn();
newColumn1.AllowDBNull = false;
newColumn1.Caption = "three letter ISO country abbreviation";
newColumn1.ColumnName = "iso";
newColumn1.DataType = System.Type.GetType("System.String");
countryTable.Columns.Add(newColumn1);
//note: add data columns to datatable
DataColumn newColumn2 = new DataColumn();
newColumn2.AllowDBNull = false;
newColumn2.Caption = "country name";
newColumn2.ColumnName = "countryName";
newColumn2.DataType = System.Type.GetType("System.String");
countryTable.Columns.Add(newColumn2);
//note: rename table
countryTable.TableName = "CountryList";
//note: add row
DataRow newRow1 = countryTable.NewRow();
newRow1["iso"] = "abc";
newRow1["countryName"] = "côte d'ivoire";
countryTable.Rows.Add(newRow1);
//note: add row
DataRow newRow2 = countryTable.NewRow();
newRow2 = countryTable.NewRow();
newRow2["iso"] = "xyz";
newRow2["countryName"] = "são tomé and príncipe";
countryTable.Rows.Add(newRow2);
#endregion
#region region 2: bind datatable to drop down box
ddlCountry.DataSource = countryTable;
ddlCountry.DataTextField = "countryName";
ddlCountry.DataValueField = "iso";
ddlCountry.DataBind();
#endregion
}
}