Monday, June 11, 2012

Inserting 'space' in an ASP.NET DropDownList Control

i have an ASP.NET DropDownList control that retrieves the first and last name from a column in the database. Instead of having just one space between the first and last name, I want there to be three. How do I add the extra spaces between the two pieces of text in the DropDownList?


Solution:


Add   instead of space character, and HtmlDecode all elements after binding :



string[] items = new string[] { 
    "name& nbsp;& nbsp;& nbsp;surname1", 
    "name& nbsp;& nbsp;& nbsp;surname2" };

ddl.DataSource = items;
ddl.DataBind();
foreach (ListItem item in ddl.Items)
{
    item.Text = HttpUtility.HtmlDecode(item.Text);
}


No comments: