Click here to Skip to main content
15,891,372 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi,

I have a drop down list which consist of two list item A and B, now i want to display field A only but Not B how i do it.

Please help

Thanks
Posted
Comments
Rahul Rajat Singh 17-Jul-12 3:57am    
Just a small question. If you dont want the user to see the second option and user will never be able to select it, why do you need to have 2 options in Dropdown?

HTML
<select id="mySelect">
    <option value="A">Option A</option>
    <option value="B" style="display:none;">Option B</option>
</select>


If it's a asp:DropDownList with listitem's you cant't set visible="false" or anything. You will have to rebind the list without option "B".
Or you can achieve the same with javascript (jquery):

JavaScript
function hideB() {
    $('#mySelect').find('option[value="B"]').hide();
}
 
Share this answer
 
v3
Hi,

try like this..

C#
DropDownList1.Items[1].Attributes.Add("style","display:none");


hope it works.
 
Share this answer
 
v2
Hope it works

C#
DropDownlist1.Items.insert(0,"A");
DropDownlist1.Items.Add("B");
DropDownlist1.SelectedIndex=0;
 
Share this answer
 
v2
nikil try this,
C#
DropDownlist1.Items.Remove("your Parameter Name");


Later U can add it,
C#
DropDownlist1.Items.Add("your Parameter Name");
 
Share this answer
 
v2
i very easy in Properties of drop dawn list

Data Text Field >>>> that to display field
Data value Field >>>> that to value



S.Dwaik
 
Share this answer
 
hi nikhil,

u can do like this:

.aspx code:

<asp:DropDownList ID="drp" runat="server">
<asp:ListItem Text="1" Value="1"></asp:ListItem>
<asp:ListItem Text="2" Value="2"></asp:ListItem>
</asp:DropDownList>


.aspx.cs code:

drp.Items[1].Attributes.Add("style", "display:none");

kkakadiya
 
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