Click here to Skip to main content
15,881,559 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
i add 'select' at top position (i.e. as first item) of my dropdown list.

it's like-

--SELECT--
Item1
item2
item3
item4



so i want that this 'select' become disable, how can i do this...pls give me sggetions frnds?
Posted
Updated 20-Nov-19 3:33am

The exact answer that you need is in the below link
how to avoid 'please select' in dropdown list to consider as data?[^]
 
Share this answer
 
While you are reading items from dropdown, you add below condition, this way option
--Select-- never gets executed.
C#
if (ddl.SelectedIndex != 0) // ddl being your dropdown
{
   // add your code here.   
}


OR

You can disable the button if selected index of your dropdown is zero (0).
This is assuming that you have a button click event which uses dropdown value.
 
Share this answer
 
Use jquery for Disabling the dropdown list items like below
JavaScript
$(document).ready(function() {   
   $('#ddlListId option:contains("HTML")').attr("disabled","disabled");
});​

Hope this helps
 
Share this answer
 
hi please check my ans

XML
<asp:DropDownList runat="server" ID="ddlBank">
  <asp:ListItem Text="Select" Value="" disabled="disabled" />
  <asp:ListItem Text="bank 1 " Value="bank 1"  />
  <asp:ListItem Text="bank 2 " Value="bank 2"  />
  <asp:ListItem Text="bank 3 " Value="bank 3"  />
  <asp:ListItem Text="Restaurant" Value="Restaurant" disabled="disabled" />
  <asp:ListItem Text="Test" Value="value"  />
  <asp:ListItem Text="restaurant 1" Value="restaurant 1"  />
  <asp:ListItem Text="restaurant 2" Value="restaurant 2" />
  <asp:ListItem Text="restaurant 3" Value="restaurant 3"  />
 
Share this answer
 
Use C#:
C#
ddlListId.Items.FindByValue("Item1").Attributes.Add("Disabled", "Disabled");
 
Share this answer
 

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