I'm creating SQL query editor.My idea is there is a textarea
in which user insert query like select * from tbl
and then I get text from textarea
and then put in sqlcommand
and execute query and show result in gridview.But Problem is how can I change keyword color like when user enter INSERT
or SELECT
command then automatically it change color blue
like in SQL query editor and all other keywords like SELECT
, INSERT
, UPDATE
, DELETE
and so on.How can I change color runtime in textarea.
Asked
Active
Viewed 1,986 times
0

Praveen Kumar Purushothaman
- 164,888
- 24
- 203
- 252

Hameed
- 51
- 4
- 16
-
1You may better off with using a library like [CodeMirror](https://codemirror.net/). What's it for? – Praveen Kumar Purushothaman Jun 09 '16 at 10:49
-
Can you provide me example or tutorial .I don't know how to use this library – Hameed Jun 09 '16 at 10:51
-
I'm working in ASP.NET C#.Visual studio 2010 – Hameed Jun 09 '16 at 10:51
-
@Ashley did you click Praveen's link? It goes straight to the documentation. – Rory McCrossan Jun 09 '16 at 10:57
-
A naive approach would contain a background worker which scans the content of the textarea for keywords over and over again, and reacts in a certain way... – Ben Win Jun 09 '16 at 10:59
-
I want this in `textarea` because i get this text and put in `sqlcommand` – Hameed Jun 09 '16 at 11:00
-
@Rory I check link but using this i can't get text from this technique.Can any one provide me example how can i use this technique in visual stduio asp.net c# – Hameed Jun 09 '16 at 11:07
-
@BenWin You right 100%.But How can i do this? – Hameed Jun 09 '16 at 11:07
-
If I'm understanding you, you're trying to implement syntax highlighting? It's not possible to color portions of the text within a ` – Daniel Beck Jun 09 '16 at 14:10
-
@DanielBeck Can you provide me links? – Hameed Jun 09 '16 at 14:13
-
Provide you links to what? – Daniel Beck Jun 09 '16 at 14:14
-
@DanielBeck which may help me out and resolve my problem.You great.I want this.Highlight keywords – Hameed Jun 09 '16 at 14:17
-
The links already provided to you by Praveen and Vish should be enough to get you started: either use existing code (such as the one Praveen suggested) or implement your own (per the answers in the question Vish linked to below). – Daniel Beck Jun 09 '16 at 14:22
2 Answers
0
You can try it using css . Note-Change color to any choice(this one is red):
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
<style type="text/css">
input, select, textarea{
color: #ff0000;
}
textarea:focus, input:focus {
color: #ff0000;
}
</style>
</head>
<body>
<form id="form1" runat="server">
<textarea id="textarea" cols="20" name="S1" rows="2"></textarea></p>
</body>
</html>
Update
I thought to try but you can get this is already done :
http://stackoverflow.com/questions/37139076/change-color-of-specific-words-in-textarea

Vicky
- 2,027
- 1
- 19
- 31
-
Thanks for help .But You not understand my question well.My question is how to change text color for every keywords at run time.For example if write `SELECT` then it green and other text not green it's normal.ONLY KEYWORDS will be green like `SELECT`,`INSERT`,`DELETE`,`UPDATE` etc.I'm not asking for whole text color red. – Hameed Jun 09 '16 at 11:11
-
-
-
Does that link helped? if not it will take time to write alternative solution(i.e . basically what ben said-a backgroundworker process) – Vicky Jun 09 '16 at 11:17
-
Thanks Vish.I try your provided link solution.When i execute its running but problem is color not changing – Hameed Jun 09 '16 at 11:54
-
-
-
Can you help me on teamviwer please.here is my email `ashley168878@gmail.com ` – Hameed Jun 09 '16 at 12:14
-1
You said it's a c#/javascript problem so i assume it's a web site on the client side. If so i don't think you are able to change color of each individual word in an textarea but you should use some 3 party plugins to get an "improved" textarea or use other tags to achieve this functionality
-
I try this link solution `http://stackoverflow.com/questions/37139076/change-color-of-specific-words-in-textarea' but When i execute its running but problem is color not changing – Hameed Jun 09 '16 at 11:55
-
It's not changing because you are matching value form the text area against those if statements. If you write only one word, let's say SELECT it will color it but after that everything else you type even space wont match anything in the if statements because the value won't match. You need some kind of plugin or nest html tags inside each other to accomplish what you need – Proxy Jun 09 '16 at 11:59
-
I just noticed that the answer for that question is what you need more or less. You can copy it and adjust as you see fit – Proxy Jun 09 '16 at 12:12
-
-
Help with what? You just need to copy&pate that code into your own, i just tested it and it works fine. Can you elaborate where the problem is? Here you can see that it is working http://jsbin.com/xikikamufa/3/edit?html,css,js,output – Proxy Jun 09 '16 at 12:15
-
I copy paste but not working.I'm using first solution.It's running but color not changing – Hameed Jun 09 '16 at 12:16
-
-
-
I can see only the 2 picture. Have you included the css file as well in your application? – Proxy Jun 09 '16 at 12:34
-
Yes i have css code in aspx file.Here you can see http://i68.tinypic.com/140cc1t.png – Hameed Jun 09 '16 at 12:45
-
-
I'm getting div with background color black when i write `SELECT` and press space then color not changing of `SELECT` – Hameed Jun 09 '16 at 13:07
-
Does it color the syntax when you only type select? Maybe the jquery is not loading check if there are any error in the chrome console (or some other browser you are using) – Proxy Jun 09 '16 at 13:14
-
No it's not color the syntax when i write `SELECT` and how can i check chrome console? – Hameed Jun 09 '16 at 13:26
-