Click here to Skip to main content
15,881,413 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
In our ASP.Net application (*NOT* MVC), we have a Kendo-UI dropdownlist that is populated in the Default.master file. The control itself is populated in an external "global" assembly, and I cannot alter the code in that assembly.

I want to remove an item from the ddl, but NOT from the collection the ddl is bound(?) to.

EDIT 2020.02.14 =============================

I fingered it out, but I'm not at work, and don't remember what it was that fixed it. I'll verify it on Tuesday (we have Monday off). I seem to remember that I needed to change the selector to something like
JavaScript
"#[ID*='ddlList']"


What I have tried:

I tried adding the following to the script section of the Default.master file:

JavaScript
$("#ddlList option[value='2']").remove();

and this:
JavaScript
$("#ddlList option[value='2']").hide();

and also this:
JavaScript
$("#ddlList").ajaxComplete(function()
{
    $("#ddlList option[value='2']").remove();
}


EDIT =================

I also tried this (because of the arbitrary id decoration that ASP.Net does):

JavaScript
$("[ID*='ddlList'] option[value='2']").hide();


BTW, I have verified that the ddl contains the option I'm looking for, but hiding/disabling it doesn't seem to have any effect.

EDIT ======================

This:
JavaScript
$("[ID*='ddlList']").find("option.contains('2')").hide();

actually changes the desired option to this:
HTML
<option value="2" style="display:none;">2</option>
but the item is STILL displayed in the dropdown.
Posted
Updated 16-Feb-20 5:25am
v8
Comments
ZurdoDev 14-Feb-20 9:35am    
$("#ddlList option[value='2']").remove(); will work so just debug it. But why do you have it in .ajaxComplete?
#realJSOP 14-Feb-20 10:11am    
It was something i tried, without any basis in experience. IOW, it was a stab in the dark.
ZurdoDev 14-Feb-20 10:16am    
So do the code but not in ajaxComplete. I doubt that event is running. Just add the code from whatever function you have where you want to remove it.
Richard Deeming 14-Feb-20 9:42am    
The documentation suggests you can't remove an item without removing it from the data source. Perhaps you could use a custom template to hide or disable it instead?
ZurdoDev 14-Feb-20 10:17am    
Hard to believe that since jquery is on the client side and anything can be changed there without the server knowing. It may end up causing problems with the model when posting back but I doubt that.

1 solution

$("#ddlList option[value='2']").remove();
$("#ddlList option[value='2']").hide();
both working fine.
 
Share this answer
 
Comments
#realJSOP 14-Feb-20 11:27am    
not working here.
ZurdoDev 14-Feb-20 13:54pm    
Which probably means your selector is wrong or your code is not actually executing. Either way, you'll have to debug it since we can't run your code.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900