Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Special ASCII characters in ASP.NET DropDownList Control

Posted on 2010-09-05
9
Medium Priority
?
1,598 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 
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
 
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

CHALLENGE LAB: Troubleshooting Connectivity Issues

Goal: Fix the connectivity issue in the lab's AWS environment so that you can SSH into the provided EC2 instance.  

Question has a verified solution.

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

User art_snob (http://www.experts-exchange.com/M_6114203.html) encountered strange behavior of Android Web browser on his Mobile Web site. It took a while to find the true cause. It happens so, that the Android Web browser (at least up to OS ver. 2.…
Problem Hi all,    While many today have fast Internet connection, there are many still who do not, or are connecting through devices with a slower connect, so light web pages and fast load times are still popular.    If your ASP.NET page …
This is my first video review of Microsoft Bookings, I will be doing a part two with a bit more information, but wanted to get this out to you folks.
Sometimes it takes a new vantage point, apart from our everyday security practices, to truly see our Active Directory (AD) vulnerabilities. We get used to implementing the same techniques and checking the same areas for a breach. This pattern can re…

688 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