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
?
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);
}
I had this same question, thanks. I did however want to offer one suggestion.
If there's any chance you have an ampersand (&) or other special characters in your data, doing it this way is going to result in your name look like John & Jane instead of John & Jane.
So might be better to do it this way:
ListItem li = new ListItem("Fname" +HttpUtility.HtmlDecode(" ") +"Lname", id);
ddlSearchCategories.Items.Add(li);
Might want to use String.Format instead of +
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With