Click to See Complete Forum and Search --> : Columned ListBox


zabolots
October 8th, 2003, 03:03 PM
I'm tyring to simulate a columned list box on a web form using space chars to evenly distribute the list box contents.

(As I'm writing this question I can't even have this page correctly display what I'm after because the browser takes the multiple spaces and truncates them down to a single space. What I'm after is the following, but with each '_' replace with a space char.)


Joe Smith______Male____555-1212
Pete Peterson__Male____555-1313
Jane Doe_______Female__555-1414


The problem is that when I add strings to the listbox which have the correct number of spaces they're not rendered correctly since the browser treats multiple whitespace chars as a single space.

Is there any way to tell the browser to not compress the whitespace in the list item text?

underminus
October 21st, 2003, 08:57 AM
FINALLY!!! I Know so many people have had this problem. But finally i solved it with your basic mono spacing font type.

As we all know the asp.net listbox has a problem with truncating all added spaces. So you can't create columns with in your listbox. But all your need to do is use the command Sever.HtmlDecode(string) that will send whatever is in inside it directly to html. The problem was there listbox would change the & to amp; so the spaces wouldn't come out. But with this command the & will not get changed. The space html ascii to use would either be   or   just put either inside your Server.HtmlDecode() and your set.. Walla Spacing.......

Here is an example i'm using and Sql server to get data but you should get the idea.

{
Dim dreader As SqlClient.SqlDataReader
Dim sqlcmd As SqlClient.SqlCommand = New SqlClient.SqlCommand("SELECT tm_tax_code, tm_tax_description FROM [Tax-Master] ORDER BY tm_tax_code", conn1)
sqlcmd.Connection.Open()
dreader = sqlcmd.ExecuteReader

Dim TaxCode As String
Dim taxnum As Integer = 8
Dim tempspace As String
Dim ct As Integer
ct = 0

Do While dreader.Read
TaxCode = Trim(dreader("tm_tax_code"))
taxnum -= Len(TaxCode)
For ct = 0 To taxnum
tempspace = tempspace & " "
Next

LstTaxMaster.Items.Add(Trim(dreader("tm_tax_code")) & Server.HtmlDecode(tempspace) & dreader("tm_tax_description"))
tempspace = ""
taxnum = 8
Loop

sqlcmd.Connection.Close()
}

hope that helps everyone i know it was driving me nuts.


chad