Click here to Skip to main content
14,454,989 members
Rate this:
Please Sign up or sign in to vote.
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
"#[ID*='ddlList']"


What I have tried:

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

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

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

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


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

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

$("[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:
$("[ID*='ddlList']").find("option.contains('2')").hide();

actually changes the desired option to this:
<option value="2" style="display:none;">2</option>
but the item is STILL displayed in the dropdown.
Posted
Updated 16-Feb-20 6: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.
Richard Deeming 14-Feb-20 10:22am
   
For Kendo UI, it looks like the model's in Javascript as well. I don't know whether changes get sent back to the server, but I was assuming John didn't want to remove the item from the client-side collection.

Although I guess that could just be the MVC version; perhaps the WebForms version works differently.
Richard Deeming 14-Feb-20 10:29am
   
Are you using a Kendo.data.DataSource[^] to bind the list? It looks like you might be able to use the filter[^] property to filter out the item you don't want.
#realJSOP 14-Feb-20 11:27am
   
ummm, I don't know - I gotta dig through this spaghetti code to find it. again.

1 solution

Rate this:
Please Sign up or sign in to vote.

Solution 1

$("#ddlList option[value='2']").remove();
$("#ddlList option[value='2']").hide();
both working fine.
   
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, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100