473,325 Members | 2,872 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,325 software developers and data experts.

DropDown List eliminate intermediate spaces

Hello,

I'm using a dropdownlist web control. This dropdownlist has a problem with
some descriptions I'd like to show.

The description is "XXX JJJ", but it shows in the browser "XXX JJJ" (it
hides some spaces).

I tryed to encode it replacing the blanks with   but the dropdownlist
component replace de & with "&" and it makes a desaster.

I don't want to change the dropdownlist web form, any idea???

Any idea to solve this problem?

Thanks,

Pablo Difrieri.
Nov 17 '05 #1
11 4005
Hi Lucas,

Please change the HTML code manually to the following code snippet and test
this issue again. It works on my side.
...
<asp:dropdownlist id="DropDownList1" style="Z-INDEX: 102; LEFT: 288px;
POSITION: absolute; TOP: 64px"
runat="server" Height="120px" Width="208px">
<asp:ListItem Value="Test1"
Selected="True">XXX&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;J JJ</asp:ListItem>
<asp:ListItem Value="test2">test2</asp:ListItem>
</asp:dropdownlist></FONT></form>
...
Does it answer your question? If I have misunderstood your concern, please
feel free to let me know.

Best regards,

Jacob Yang
Microsoft Online Partner Support
Get Secure! ¨C www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.

Nov 17 '05 #2
We had test it and it is shown fine in the browser. The problem is that we
are using the dropdownlist binded to a Dataset, so is difficult to intercept
the render (and we think it could be difficult to do it in all our
dropdownlist controls).

Supposing we unbind the control and add items manually, we'd like to use
codebehind to do it (you can get it in the attach file) because it is part
of the standard we have to apply.

DropDownList1.Items.Add(New ListItem("XXX&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;JJJ",
"Test1"))
DropDownList1.Items.Add(New ListItem("XXX&nbsp;&nbsp;&nbsp;JJJ", "Test2"))

DropDownList1.Items.Add(New ListItem("PPP JJJ", "Test3"))

DropDownList1.Items.Add(New ListItem("PPP JJJ", "Test4"))

In this way, the first two elements encode the &nbsp; and show them
literally. The second two elements eliminates additional spaces.

Any solution to this problem?
The best solution would be that IE doesn't eliminates intermediate blank
spaces. The others are just workarounds.

Thanks a lot.

Pablo Difrieri

"Jacob Yang [MSFT]" <ji***@online.microsoft.com> escribió en el mensaje
news:Hl**************@cpmsftngxa06.phx.gbl...
Hi Lucas,

Please change the HTML code manually to the following code snippet and test this issue again. It works on my side.
..
<asp:dropdownlist id="DropDownList1" style="Z-INDEX: 102; LEFT: 288px;
POSITION: absolute; TOP: 64px"
runat="server" Height="120px" Width="208px">
<asp:ListItem Value="Test1"
Selected="True">XXX&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;J JJ</asp:ListItem>
<asp:ListItem Value="test2">test2</asp:ListItem>
</asp:dropdownlist></FONT></form>
..
Does it answer your question? If I have misunderstood your concern, please
feel free to let me know.

Best regards,

Jacob Yang
Microsoft Online Partner Support
Get Secure! ¨C www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.



Nov 17 '05 #3
Hi Lucas,

Please try the following code on your side.
...
Dim myWriter As New StringWriter
Dim myString As String
HttpUtility.HtmlDecode("PPP     JJJ",
myWriter)

myString = myWriter.ToString()
DropDownList1.Items.Add(New ListItem(myString, "Test3"))
...

Does it answer your question? If I have misunderstood your concern, please
feel free to let me know.

Best regards,

Jacob Yang
Microsoft Online Partner Support
Get Secure! ¨C www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.

Nov 17 '05 #4
OK. That works for control fulfilled manually.
Can we do something like that using databinding? Is this the cleanest
solution? I mean, the fact that the spaces were replaced, Is the correct /
expected behavior?

Thanks a lot

Pablo Difrieri
"Jacob Yang [MSFT]" <ji***@online.microsoft.com> escribió en el mensaje
news:BR**************@cpmsftngxa06.phx.gbl...
Hi Lucas,

Please try the following code on your side.
..
Dim myWriter As New StringWriter
Dim myString As String
HttpUtility.HtmlDecode("PPP     JJJ",
myWriter)

myString = myWriter.ToString()
DropDownList1.Items.Add(New ListItem(myString, "Test3"))
..

Does it answer your question? If I have misunderstood your concern, please
feel free to let me know.

Best regards,

Jacob Yang
Microsoft Online Partner Support
Get Secure! ¨C www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.

Nov 17 '05 #5
Hi Lucas,

My solution is the cleanest in the solutions I can find. Based on my
research and experience, I would like to share the following information
with you.

1. In the HTML world, the space is a special character and should be
presented as "&nbsp;" or " ". If we just use some spaces directly in
the HTML code, IE will do some unexpected behavior.

2. For reliable HTTP transmission from the Web server to a client, ASP.NET
converts a string into an HTML-encoded string.

3. In the HTML world, the "&" is also a special character and should be
presented as "&amp;". That is the reason why "&nbsp;" is converted to
"&amp;nbsp;".

In the data binding case, I think, we can make use of the Replace method
from the RegEx class to replace any space inside the values to be bound to
the dropdownlist with " " by iterating the data source before doing
the real binding. Here is the sample code to use the Replace method,

temp = "Miranda " + i.ToString()
rex = New Regex(" ")
temp = HttpUtility.HtmlDecode(rex.Replace(temp, " "))

Does it answer your question? If I have misunderstood your concern, please
feel free to let me know.

Best regards,

Jacob Yang
Microsoft Online Partner Support
Get Secure! ¨C www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.

Nov 17 '05 #6
That's OK. The point that it is not clear for me is how can I intercept the
automatic fill of the ListBox that makes the data binding. I understand the
that I need to replace the ordinal spaces for &nbsp; or the 160 character
and how to do it with manually filled ListBoxes, but where must I put the
replacement code you send me when I'm using data binding?

Thanks a lot.

LucasC

"Jacob Yang [MSFT]" <ji***@online.microsoft.com> escribió en el mensaje
news:2R**************@cpmsftngxa06.phx.gbl...
Hi Lucas,

My solution is the cleanest in the solutions I can find. Based on my
research and experience, I would like to share the following information
with you.

1. In the HTML world, the space is a special character and should be
presented as "&nbsp;" or " ". If we just use some spaces directly in
the HTML code, IE will do some unexpected behavior.

2. For reliable HTTP transmission from the Web server to a client, ASP.NET
converts a string into an HTML-encoded string.

3. In the HTML world, the "&" is also a special character and should be
presented as "&amp;". That is the reason why "&nbsp;" is converted to
"&amp;nbsp;".

In the data binding case, I think, we can make use of the Replace method
from the RegEx class to replace any space inside the values to be bound to
the dropdownlist with " " by iterating the data source before doing
the real binding. Here is the sample code to use the Replace method,

temp = "Miranda " + i.ToString()
rex = New Regex(" ")
temp = HttpUtility.HtmlDecode(rex.Replace(temp, " "))

Does it answer your question? If I have misunderstood your concern, please
feel free to let me know.

Best regards,

Jacob Yang
Microsoft Online Partner Support
Get Secure! ¨C www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.

Nov 17 '05 #7
Hi Lucas,

I am sorry if there is any misunderstanding.

Based on my research and experience, there are two ways to implement the
workaround:

1. Iterate each listitem inside the dropdownlist web control after the
databinding, and replace each space in the text of each item with "&#160".
For example,

DropDownList1.DataSource = dv
DropDownList1.DataTextField = "Employee"
DropDownList1.DataValueField = "EmployeeID"
DropDownList1.DataBind()

Dim myitem As ListItem

For Each myitem In DropDownList1.Items
temp = HttpUtility.HtmlDecode(rex.Replace(myitem.Text,
" "))
myitem.Text = temp
Next

2. Iterate each row of the datatable before binding to the dropdownlist,
and replace each space in each field with "&#160", and then bind the
modified datable to the dropwodnlist.

Please let me know if it helps.

Best regards,

Jacob Yang
Microsoft Online Partner Support
Get Secure! ¨C www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.

Nov 17 '05 #8
My last question. Which event allow me to "Iterate each listitem inside the
dropdownlist web control after the databinding"?
Thanks a lot Jacob.

LucasC

"Jacob Yang [MSFT]" <ji***@online.microsoft.com> escribió en el mensaje
news:JP**************@cpmsftngxa06.phx.gbl...
Hi Lucas,

I am sorry if there is any misunderstanding.

Based on my research and experience, there are two ways to implement the
workaround:

1. Iterate each listitem inside the dropdownlist web control after the
databinding, and replace each space in the text of each item with "&#160".
For example,

DropDownList1.DataSource = dv
DropDownList1.DataTextField = "Employee"
DropDownList1.DataValueField = "EmployeeID"
DropDownList1.DataBind()

Dim myitem As ListItem

For Each myitem In DropDownList1.Items
temp = HttpUtility.HtmlDecode(rex.Replace(myitem.Text,
" "))
myitem.Text = temp
Next

2. Iterate each row of the datatable before binding to the dropdownlist,
and replace each space in each field with "&#160", and then bind the
modified datable to the dropwodnlist.

Please let me know if it helps.

Best regards,

Jacob Yang
Microsoft Online Partner Support
Get Secure! ¨C www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.

Nov 17 '05 #9
Hi Lucas,

There is not a special event for this implementation. We can do the
listitem iteration either immediately after the call to the databind()
method, or inside the PreRender event of the dropdownlist web control,
where the databinding has been finished.

I hope it helps.

Best regards,

Jacob Yang
Microsoft Online Partner Support
Get Secure! ¨C www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.

Nov 17 '05 #10
Thanks a lot

LucasC.
"Jacob Yang [MSFT]" <ji***@online.microsoft.com> escribió en el mensaje
news:q5**************@cpmsftngxa06.phx.gbl...
Hi Lucas,

There is not a special event for this implementation. We can do the
listitem iteration either immediately after the call to the databind()
method, or inside the PreRender event of the dropdownlist web control,
where the databinding has been finished.

I hope it helps.

Best regards,

Jacob Yang
Microsoft Online Partner Support
Get Secure! ¨C www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.

Nov 17 '05 #11
In my case it doesnt behave this funky...

Keyur Shah
Verizon Communications
732-423-0745

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Nov 17 '05 #12

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Joseph Barron | last post by:
Here is a SIMPLE problem that I'm trying to solve. It works in Netscape 6.2, but IE6 gives ""No such interface supported." Below are page1.htm and page2.htm . In page1.htm, there are two...
1
by: relaxedrob | last post by:
Hi All, I want to write a select control and use a Javascript function to handle all click events on the control. Under certain circumstances I also wish to prevent the dropdown's list from...
5
by: Nick Calladine | last post by:
Learning : Loop to list all dropdown box values on a form Can some one point me in the right direction : I have a form which I want to loop through I basically want to get all the selected...
1
by: maxmarengo | last post by:
I am trying to write a query in Access (or SQL) that works on a table like this: Location Gridreference Ben Nevis NQ1234512345 Ben Doon NQ1230012300 and so on for several thousand...
3
by: Tim Mavers | last post by:
I am looking for a control (freeware or commercial) that operates like a standard ASP.NET dropdown list, but is able to display heirarchies in the actual dropdown list. This can be similar to a...
0
by: kinane3 | last post by:
Mostly I need to figure if I'm wasting my time or if there is a way to do what I am trying to do. I am an intermediate to CSS at best so please don't flame me, just trying to do my job here. I...
12
by: jea | last post by:
First, sorry for poor English. I hav the following task: In a Mysql I have a table of events. An event is described in 3 fields: date, place, activity. Now I want to build a dropdown list where...
3
by: groups2 | last post by:
When you press the down key while in an input field the default behavior for some event creates a dropdown of the previously input text. What event creates that behavior and how do I stop it ? ...
4
by: Peter | last post by:
Does anyone know of OpenSource .NET 2.0 ajax dropdown box with typeahead feature and ability to load only X amount of items? I have over 20,000 names in a database table which I would like to...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.