Solved

Special ASCII characters in ASP.NET DropDownList Control

Posted on 2010-09-05
9
1,547 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
3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

 
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

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

This document covers how to connect to SQL Server and browse its contents.  It is meant for those new to Visual Studio and/or working with Microsoft SQL Server.  It is not a guide to building SQL Server database connections in your code.  This is mo…
Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
You have products, that come in variants and want to set different prices for them? Watch this micro tutorial that describes how to configure prices for Magento super attributes. Assigning simple products to configurable: We assigned simple products…
A short film showing how OnPage and Connectwise integration works.

930 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

10 Experts available now in Live!

Get 1:1 Help Now