Hi, I'm working with ASP.NET 1.1, and I'm having trouble getting data to display a certain way in a ListBox.
I want data listed in the ListBox to be indented if the item is part of a sub-category. For example, if I have a main category called "Three Stooges", then I want the phrase "Three Stooges" to be flush left in the ListBox, and the next four sub-items, "Larry", "Moe", "Curly" and "Shemp", to be listed with five indented spaces in front of each name. The next main category could be "Marx Brothers", flush left, and then the names of each Marx brother would listed below with five spaces in front of each name.
The following code didn't work. The data was automatically trimmed by the ListBox control after binding the DataTable to the control.
foreach(DataRow row in objDataTable.Rows)
{
if(row["Comedian"].ToString() == "Curly")
row["Comedian "] = " Curly";
}
The code below also did not work. The non-breaking space characters, " ", were actually displayed in the ListBox.
foreach(DataRow row in objDataTable.Rows)
{
if(row["Comedian"].ToString() == "Curly")
row["Comedian "] = " Curly";
}
I'd appreciate any advice you can offer to help me accomplish this task.
Thanks in advance!
you can use a chr(160) to get nbsp's into a ddl
row["Comedian "] = chr(160) + chr(160) + chr(160) +chr(160) + chr(160) + "Curly";
Thanks for the reply! A friend sent me the following C# function which is working great:
publicstaticstring DecodedSpaces(int NumberOfSpaces)
{
string strSpaces =string.Empty;
for (int i = NumberOfSpaces; i > 0; i--)
{
strSpaces += " ";
}
return System.Web.HttpUtility.HtmlDecode(strSpaces);
}
That HtmlDecode part is the key (since it will be re-encoded when the listbox displays it); however, if you need to use this in browsers other than Internet Explorer, you'll want to make sure they behave the same way.
Good advice. Thanks.
For what its worth, the value returned from
System.Web.HttpUtility.HtmlDecode(" ");
is actually a Chr(160)
here's a list of other html character entities that you may someday find usefull
http://en.wikipedia.org/wiki/List_of_XML_and_HTML_character_entity_references
mbanavige:
For what its worth, the value returned from
System.Web.HttpUtility.HtmlDecode(" ");
is actually a Chr(160)
You know, I actually thought I had mentioned that in my post! Apparently my brain got too far ahead of my fingers...
The nice part about using HtmlDecode is that you don't have to go looking up the characters... but of course either way gets the job done.
0 comments:
Post a Comment