Special ASCII characters in ASP.NET DropDownList Control

Posted on 2010-09-05
Last Modified: 2013-11-08
Dear experts,

I have the following piece of code on my ASP.NET web form:

<asp:DropDownList ID="CommandLineTerminatorList" runat="server" SelectedValue='<%# Bind("CommandLineTerminator") %>' ValidationGroup="NewValidators">
	<asp:ListItem Value="<%=vbCr%>">&lt;CR&gt;</asp:ListItem>
	<asp:ListItem Value="<%=vbCrLf%>">&lt;CR&gt;&lt;LF&gt;</asp:ListItem>

Open in new window

I would like the Values to be saved in the database as the actual ASCII characters i.e. vbCr should be saved as the Carriage Return Character (ASCII 13) and vbCrLf should be saved as a Carriage Return + Line Feed (ASCII 13 and ASCII 10) Characters. At the moment, the values are being stored as strings "<%=vbCr%>" and "<%=vbCrLf%>"
Question by:bmatumbura
  • 5
  • 3
LVL 11

Author Comment

ID: 33609304
By the way, I prefer a solution that does this from markup (and not from the code-behind file). I already have a work-around that uses the code-behind file.

Expert Comment

ID: 33609508
Just I think:
1. have you tried instead of Value="<%=vbCr%>"> to put Value="Chr(13)" and Value="Chr(10)" for Line Feed.
I'm not quite sure what you mean with ASCII characters for Carrige return and Line feed. There are no "visual" presentation of those to things. You can see only a little square box instead of them. So you can save them on some other way.
2. For example in database you can save some other data for CR and LF (instead of pure ascii values): for example for CR you can store just "CR" and for LF save "LF". Then when you need to present "back" mentioned data in some your form or page, you can make some conversion code like:
If someVar = "CR" Then showValue = vbCr.
for CRLF just replace db string CRLF with vbCrLf
Regards Peter !
LVL 11

Author Comment

ID: 33609868

TRUE, there are no visual presentations of these characters, but my code displays them as (None), <CR> and <CR><LF> in the list. What I need is to set the Value property (and not the Text property) of the DropDownList control to these values. The challenge I have is I must store the values in the db as the actual Carriage Return and Line Feed characters. I don't have control (i.e source code) of the application that uses these fields in the db hence the requirement.
Space-Age Communications Transitions to DevOps

ViaSat, a global provider of satellite and wireless communications, securely connects businesses, governments, and organizations to the Internet. Learn how ViaSat’s Network Solutions Engineer, drove the transition from a traditional network support to a DevOps-centric model.


Expert Comment

ID: 33610027
So, actually you need to store in DB cr value when you select e.g <CR> in combo ?

If so, then you have to find out how to present those "values" in your database (i.e. how those data is written in DB) !

 I know that if you want to output from Oracle the cr, you should write sql such as
SELECT Field1 || CHR(13) || Field2 from someTable Where ....
If you execute that in some db manager (like TOAD) you will see strange chartacter instead of CR. But if you pick up that result and present it on some form, you will get CR.

I don't know which DB you use, but CHR(13) should be universal for all databases (not sure).
In this case you should set the value for your combos, what ever you want - just not that what you use, and programticaly insert data into the DB.
LVL 11

Author Comment

ID: 33610140
Yes, that's what I need to store. I am using SQL 2008. All I need is how present the values in the DropDownList's .Value property.

Expert Comment

ID: 33610911
Well, some peple confirms that for carriage return should be used CHAR(13) and for Line feed CHAR(10).
See this link:

But I have done some simple insert into my test table (based on mentioned link), but when done select from that table I haven't got CR and LF.
But this depends of interface that should present data. I believe that in ASP.NET page you will get new lines.
Anyhow, try this. Also I found on some link that is used NCHAR(13) instead of CHAR(13).
LVL 11

Accepted Solution

bmatumbura earned 0 total points
ID: 34051110
Sorry, but this solution doesn't work. I managed to resolve this issue on my own by using Entity Framework in the code-behind file. I intercepted the Inserting/Updating events of the entity datasource and modified the value of the CommandLineTerminatorList field to store VBCR, VBCRLF or Nothing.
LVL 11

Author Closing Comment

ID: 34082680
Managed to resolve the issue on my own

Featured Post

DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In my previous two articles we discussed Binary Serialization ( and XML Serialization ( In this article we will try to know more about SOAP (Simple Object Acces…
For those of you who don't follow the news, or just happen to live under rocks, Microsoft Research released a beta SDK ( for the Xbox 360 Kinect. If you don't know what a Kinect is (http:…
Email security requires an ever evolving service that stays up to date with counter-evolving threats. The Email Laundry perform Research and Development to ensure their email security service evolves faster than cyber criminals. We apply our Threat…
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…

856 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question