asp.net - Select2 change Dropdownlist item colour if contains a stringAsp.net - Add blank item at top of dropdownlistHow do you create a dropdownlist from an enum in ASP.NET MVC?Case insensitive 'Contains(string)'How to check whether a string contains a substring in JavaScript?How to maintain state in (asp.net) custom server control?How do I check if string contains substring?How to find if an array contains a specific string in JavaScript/jQuery?select2 changing items dynamicallySelect2 change container positionSelect2 - Highlighted Option Background Colour Width When you have Long Strings?
Understanding "audieritis" in Psalm 94
What is the oldest known work of fiction?
How will losing mobility of one hand affect my career as a programmer?
Is it correct to write "is not focus on"?
Is the destination of a commercial flight important for the pilot?
Why does John Bercow say “unlock” after reading out the results of a vote?
How do I rename a LINUX host without needing to reboot for the rename to take effect?
Ways to speed up user implemented RK4
What is difference between behavior and behaviour
Increase performance creating Mandelbrot set in python
Centering an <li> element without taking bullet point into account
Can I use my Chinese passport to enter China after I acquired another citizenship?
Can I Retrieve Email Addresses from BCC?
What is the opposite of 'gravitas'?
Tiptoe or tiphoof? Adjusting words to better fit fantasy races
Why is delta-v is the most useful quantity for planning space travel?
Is there a good way to store credentials outside of a password manager?
Modify casing of marked letters
How was Earth single-handedly capable of creating 3 of the 4 gods of chaos?
Time travel short story where a man arrives in the late 19th century in a time machine and then sends the machine back into the past
How do I keep an essay about "feeling flat" from feeling flat?
What's the purpose of "true" in bash "if sudo true; then"
Everything Bob says is false. How does he get people to trust him?
Can somebody explain Brexit in a few child-proof sentences?
asp.net - Select2 change Dropdownlist item colour if contains a string
Asp.net - Add blank item at top of dropdownlistHow do you create a dropdownlist from an enum in ASP.NET MVC?Case insensitive 'Contains(string)'How to check whether a string contains a substring in JavaScript?How to maintain state in (asp.net) custom server control?How do I check if string contains substring?How to find if an array contains a specific string in JavaScript/jQuery?select2 changing items dynamicallySelect2 change container positionSelect2 - Highlighted Option Background Colour Width When you have Long Strings?
I have this Select 2 DropDownList:
$(document).ready(function ()
$("#<%=ddl_modelo_equipamento.ClientID%>").select2(
placeholder: "Selecione um Modelo"
);
);
And I have this Code Behind which is called based on another DropDownList Changed Value that loads the information on this select2 DropDownList:
private void changeColor(DropDownList ddl_modelo_equipamento)
foreach (ListItem item in ddl_modelo_equipamento.Items)
string descricao = item.Text;
if (descricao.Contains("; Stock: 0 unid."))
item.Attributes.Add("style", "color:red");
continue;
For each item in the DropDownList that contains this string "; Stock: 0 unid."
I want the font colour to be changed to red and it isn't changing with a Select2 DropDownList but if I change it to a normal asp DropDownList it changes the colour.
Am I doing something wrong?
javascript c# asp.net jquery-select2
add a comment |
I have this Select 2 DropDownList:
$(document).ready(function ()
$("#<%=ddl_modelo_equipamento.ClientID%>").select2(
placeholder: "Selecione um Modelo"
);
);
And I have this Code Behind which is called based on another DropDownList Changed Value that loads the information on this select2 DropDownList:
private void changeColor(DropDownList ddl_modelo_equipamento)
foreach (ListItem item in ddl_modelo_equipamento.Items)
string descricao = item.Text;
if (descricao.Contains("; Stock: 0 unid."))
item.Attributes.Add("style", "color:red");
continue;
For each item in the DropDownList that contains this string "; Stock: 0 unid."
I want the font colour to be changed to red and it isn't changing with a Select2 DropDownList but if I change it to a normal asp DropDownList it changes the colour.
Am I doing something wrong?
javascript c# asp.net jquery-select2
Because a<asp:DropDownList />
renders out a standard<select>
with<option>
's, and select2 replaces that markup with<div>
,<span>
and<ul>
's. Probably when you add that attribute it gets added to the hidden<option>
but the corresponding select2 element is un-affected.
– zgood
Mar 21 at 15:29
What code can I use to change the color of the item in Select2
– Mingo Bille
Mar 21 at 15:30
Well, for starters it would probably be better to handle this in javascript and not your code-behind. Add achange
event handler to select2 and do your update there.
– zgood
Mar 21 at 15:31
The thing is that I am really clueless about how to make this, fr
– Mingo Bille
Mar 21 at 15:38
add a comment |
I have this Select 2 DropDownList:
$(document).ready(function ()
$("#<%=ddl_modelo_equipamento.ClientID%>").select2(
placeholder: "Selecione um Modelo"
);
);
And I have this Code Behind which is called based on another DropDownList Changed Value that loads the information on this select2 DropDownList:
private void changeColor(DropDownList ddl_modelo_equipamento)
foreach (ListItem item in ddl_modelo_equipamento.Items)
string descricao = item.Text;
if (descricao.Contains("; Stock: 0 unid."))
item.Attributes.Add("style", "color:red");
continue;
For each item in the DropDownList that contains this string "; Stock: 0 unid."
I want the font colour to be changed to red and it isn't changing with a Select2 DropDownList but if I change it to a normal asp DropDownList it changes the colour.
Am I doing something wrong?
javascript c# asp.net jquery-select2
I have this Select 2 DropDownList:
$(document).ready(function ()
$("#<%=ddl_modelo_equipamento.ClientID%>").select2(
placeholder: "Selecione um Modelo"
);
);
And I have this Code Behind which is called based on another DropDownList Changed Value that loads the information on this select2 DropDownList:
private void changeColor(DropDownList ddl_modelo_equipamento)
foreach (ListItem item in ddl_modelo_equipamento.Items)
string descricao = item.Text;
if (descricao.Contains("; Stock: 0 unid."))
item.Attributes.Add("style", "color:red");
continue;
For each item in the DropDownList that contains this string "; Stock: 0 unid."
I want the font colour to be changed to red and it isn't changing with a Select2 DropDownList but if I change it to a normal asp DropDownList it changes the colour.
Am I doing something wrong?
javascript c# asp.net jquery-select2
javascript c# asp.net jquery-select2
asked Mar 21 at 15:25
Mingo BilleMingo Bille
154
154
Because a<asp:DropDownList />
renders out a standard<select>
with<option>
's, and select2 replaces that markup with<div>
,<span>
and<ul>
's. Probably when you add that attribute it gets added to the hidden<option>
but the corresponding select2 element is un-affected.
– zgood
Mar 21 at 15:29
What code can I use to change the color of the item in Select2
– Mingo Bille
Mar 21 at 15:30
Well, for starters it would probably be better to handle this in javascript and not your code-behind. Add achange
event handler to select2 and do your update there.
– zgood
Mar 21 at 15:31
The thing is that I am really clueless about how to make this, fr
– Mingo Bille
Mar 21 at 15:38
add a comment |
Because a<asp:DropDownList />
renders out a standard<select>
with<option>
's, and select2 replaces that markup with<div>
,<span>
and<ul>
's. Probably when you add that attribute it gets added to the hidden<option>
but the corresponding select2 element is un-affected.
– zgood
Mar 21 at 15:29
What code can I use to change the color of the item in Select2
– Mingo Bille
Mar 21 at 15:30
Well, for starters it would probably be better to handle this in javascript and not your code-behind. Add achange
event handler to select2 and do your update there.
– zgood
Mar 21 at 15:31
The thing is that I am really clueless about how to make this, fr
– Mingo Bille
Mar 21 at 15:38
Because a
<asp:DropDownList />
renders out a standard <select>
with <option>
's, and select2 replaces that markup with <div>
, <span>
and <ul>
's. Probably when you add that attribute it gets added to the hidden <option>
but the corresponding select2 element is un-affected.– zgood
Mar 21 at 15:29
Because a
<asp:DropDownList />
renders out a standard <select>
with <option>
's, and select2 replaces that markup with <div>
, <span>
and <ul>
's. Probably when you add that attribute it gets added to the hidden <option>
but the corresponding select2 element is un-affected.– zgood
Mar 21 at 15:29
What code can I use to change the color of the item in Select2
– Mingo Bille
Mar 21 at 15:30
What code can I use to change the color of the item in Select2
– Mingo Bille
Mar 21 at 15:30
Well, for starters it would probably be better to handle this in javascript and not your code-behind. Add a
change
event handler to select2 and do your update there.– zgood
Mar 21 at 15:31
Well, for starters it would probably be better to handle this in javascript and not your code-behind. Add a
change
event handler to select2 and do your update there.– zgood
Mar 21 at 15:31
The thing is that I am really clueless about how to make this, fr
– Mingo Bille
Mar 21 at 15:38
The thing is that I am really clueless about how to make this, fr
– Mingo Bille
Mar 21 at 15:38
add a comment |
0
active
oldest
votes
Your Answer
StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");
StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);
else
createEditor();
);
function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55283883%2fasp-net-select2-change-dropdownlist-item-colour-if-contains-a-string%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
0
active
oldest
votes
0
active
oldest
votes
active
oldest
votes
active
oldest
votes
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55283883%2fasp-net-select2-change-dropdownlist-item-colour-if-contains-a-string%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Because a
<asp:DropDownList />
renders out a standard<select>
with<option>
's, and select2 replaces that markup with<div>
,<span>
and<ul>
's. Probably when you add that attribute it gets added to the hidden<option>
but the corresponding select2 element is un-affected.– zgood
Mar 21 at 15:29
What code can I use to change the color of the item in Select2
– Mingo Bille
Mar 21 at 15:30
Well, for starters it would probably be better to handle this in javascript and not your code-behind. Add a
change
event handler to select2 and do your update there.– zgood
Mar 21 at 15:31
The thing is that I am really clueless about how to make this, fr
– Mingo Bille
Mar 21 at 15:38