Solved

Special ASCII characters in ASP.NET DropDownList Control

Posted on 2010-09-05
9
1,541 Views
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>
</asp:DropDownList>

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%>"
0
Comment
Question by:bmatumbura
  • 5
  • 3
9 Comments
 
LVL 11

Author Comment

by:bmatumbura
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.
0
 
LVL 3

Expert Comment

by:pnedic
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 !
0
 
LVL 11

Author Comment

by:bmatumbura
ID: 33609868
@pnedic,

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.
0
 
LVL 3

Expert Comment

by:pnedic
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.
0
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 
LVL 11

Author Comment

by:bmatumbura
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.
0
 
LVL 3

Expert Comment

by:pnedic
ID: 33610911
Well, some peple confirms that for carriage return should be used CHAR(13) and for Line feed CHAR(10).
See this link:http://blog.sqlauthority.com/2007/08/22/sql-server-t-sql-script-to-insert-carriage-return-and-new-line-feed-in-code/

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).
0
 
LVL 11

Accepted Solution

by:
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.
0
 
LVL 11

Author Closing Comment

by:bmatumbura
ID: 34082680
Managed to resolve the issue on my own
0

Featured Post

What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

IntroductionWhile developing web applications, a single page might contain many regions and each region might contain many number of controls with the capability to perform  postback. Many times you might need to perform some action on an ASP.NET po…
Many of us here at EE write code. Many of us write exceptional code; just as many of us write exception-prone code. As we all should know, exceptions are a mechanism for handling errors which are typically out of our control. From database errors, t…
Here's a very brief overview of the methods PRTG Network Monitor (https://www.paessler.com/prtg) offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…
This demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.

706 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

Need Help in Real-Time?

Connect with top rated Experts

22 Experts available now in Live!

Get 1:1 Help Now