.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
Sign In
Win Surprise Gifts!!!

Top 5 Contributors of the Month
Gaurav Pal
Post New Web Links

How can I get attribute value of option in dropdownlist

Posted By:      Posted Date: September 20, 2010    Points: 0   Category :ASP.Net
<select id="mySelect">
<option value="1" level="2">Nothing</option>

To get value, i used: $("#mySelect").val() (=1)

BUT... How can I get level value? (=2)

View Complete Post

More Related Resource Links

Selected Option from dropdownlist

 I need to figure out a way to modify the style property of a div on my page so that when a certain item ("Not shown - please quote") on a few different dropdownlists are selected,  the div style is set to "display: none". The dropdownlist gets generated dynamically and the amount of dropdownlists varys for each product. I've named the class via the cssclass property in the dropdownlist template usercontrol to be "dropDownClass".Here is my code for this page: <div id="ProductControls"> <div id="ProductOptions"> <div id="ctl00_MainContentHolder_VariantsDisplay_VariantsPanel" class="variantsdisplay"> <table> <tr class="dropdownlist"> <td class="choicelabel"><span id="ctl00_MainContentHolder_VariantsDisplay_modifierTemplate1_InputLabel">Color</span></td> <td class="choicefield"><select name="ctl00$MainContentHolder$VariantsDisplay$modifierTemplate1$ModifierList" onchange="javascript:setTimeout('__doPostBack(\'ctl00$MainContentHolder$VariantsDisplay$modifierTemplate1$ModifierList\',\'\')', 0)" id="ctl00_MainContentHolder_VariantsDisplay_modifierTemplate1_ModifierList" clas

Dropdownlist is accepting 'selected', but isn't rendering that option as selected


I thought this would be pretty simple, and in fact it's working on another dropdownlist on the same View, so I'm hoping I missed something very small that is easy to fix. Here's my code:

<% List<SelectListItem> activeListItems = new List<SelectListItem>();
                           activeListItems.Add(new SelectListItem { 
                                Text = "Select Status",
                                Value = ""
                           activeListItems.Add(new SelectListItem
                               Text = "Active",
                               Value = "1",
                               Selected = (Model.Active == true)
                           activeListItems.Add(new SelectListItem
                               Text = "Inactive",
                               Value = "0",
                               Selected = (Model.Active == false)

                        <%: Html.DropDownListFor(model => model.Active, activeListItems) %>
                        <%: Html.ValidationMessageFor(model => model.Active) %>

When I

I'm trying to change the contents of a dropdownlist when a user selects option 0 = "Other"


I'm attempting to change my select statement when a selection of "Other" is detected. The problem is that the select that executes on the page is always the original selection from the datasource definition. I've found an example where the "SelectCommand" value is changed in the code behind, but it is for a case where the dropdownlist is not in a template. I'm thinking that I have to bind to the template, but I'm not getting it to work.  (see the last couple of lines in the Page_Load code)

 asp code:


                <asp:DetailsView AutoGenerateRows="False" DataKeyNames="EmployeeTimeId" DataSourceID="sdsEmpTimeDetailsView"

                    DefaultMode="Insert" HeaderText="Add EmployeeTime"



not getting option elements in dropdownlist



i am using two dropdownlist.firstone is for getting options and second for getting elements for the selected options.i have write function in javascript,but i am not geting the elements for options.please help me with is error.



my html code is:

<td style="width:20%; height:25px; margin-left: 120px;">
                             <asp:DropDownList ID="DropDownList3" runat="server" style="height: 22px; width: 75%;" TabIndex="2"
                             Font-Names="Verdana" Font-Size="11px" AutoPostBack="True"  onChange="dropdown1(this,$get('ctl00_ContentPlaceHolder1_DropDownList2'))">

Dropdownlist Set Selected item option


Hi Guys,

i have a dropdown list that is dynamically populated from a database. it has an Value(ID) field and an Option(Text) field.

I want to use jquery to set the dropdownlist to the Option dynamically.

$("#dropdownlist option:selected").val("Text");

Aove line of code doesn't work?

Any ideas?

Populate a dropdownlist with an XML attribute


I'm able to access the node without problems, but how do I access the attribute of the node?

Dim xnl As System.Xml.XmlNodeList = xd.GetElementsByTagName("track")
For i As Integer = 0 To xnl.Count - 1

<track source="/here/there/" artist="Jack D"  />

jQuery: Styling DropDownList Alternating Items (Rows)

In the following example, I will show how you can style any asp:dropdownlist very easily.

The example demonstrates how you can change alternating row items background color, using the fadeTo() to add a nice touch in the dropdownlist. You can change alt rows with a couple lines.

Working with DropDownList and ListBox Controls in ASP.NET

"In my application i am using dropdownlist to display all categories from a table. When the user clicks this control I display all records in that category. Category table also contains column called color.

I wanted display some categories in dropdown list different color and others in different color using ASP.NET."-Anonymous

ASP.NET DropDownList Web Control, Part 1

Anybody with much experience in ASP has written an include file function for populating the contents of a SELECT dropdown list with entries from a database. Some of the more advanced users have even gone so far as to add caching to their function to reduce database hits for these rarely changing menu options. Naturally, these same techniques are going to be used with ASP.NET, but with a new programming object model. ASP.NET provides a web control, the DropDownList, which can be used for the same purposes as our custom built SELECT tag from Classic ASP.

Declaring a DropDownList in ASP .Net

A DropDownList is also commonly known as combo box. It can contain multiple data members, but unlike a normal list box the users can choose only one value from this control. Though the functionality of this DropDownList is much like a Single Row Select List Box, a DropDownList can save a lot of GUI space as it is rendered on a Single line and is expanded only when the user clicks on the Control

Multiple Column Dropdownlist for the ASP.NET DataGrid

Based on my previous control "Multiple Column DropDownList for ASP.NET", I received many emails asking for the same control to be used in the DataGrid for web applications. Here we go.. This control can be used as the regular MS DropDownList in the DataGrid and also as a regular dropdownlist. It has all the properties, like DataTextField, DataValueField, DataSource, SelectedIndex etc. The download file contains the samples both in VB.NET and C#. In this sample, I have used the Northwind database of SQL Server.

ASP.NET Multiple Selection DropDownList with AJAX HoverMenuExtender

Recently, I was looking for a multiple selection dropdownlist control for my new project. After spending some time researching for it, I decided to put together all my finding in one web user control. This web user control consists of an ASP.NET AJAX HoverMenuExtender, JavaScript, StyleSheet and CheckBoxListExCtrl . The final product will work with or without a MasterPage and you can drag and drop more than one instances of the control on to the page.

How to bind GridView and DropDownList controls using DataTable object

In .net framework 2.0, you can load a DataTable in memory by consuming a data source using a DataReader. In this version you will find the flexibility in accessing the DataReader means write access code once and use again and again using DataReader. To see the functionality of DataTable consider an example that is created using VS2005.

How to bind TemplateField DropDownList with ArrayList?


Hi Expert!

  I'm trying gridview templateField DropDownList bind with arraylist. When i set bindsource i got this error. "//Error Object reference not set to an instance of an object."

My Sample .aspx

<asp:TemplateField HeaderText="Type">
                        <asp:DropDownList ID="_grvcboType" runat="server" Width="117px" DataTextField="Display" DataValueField="Value">
                        <asp:Label ID="Label7" runat="ser

how to make a dropdownlist looks like google search box


dear all...

any idea how to do that ?

Thnx in advance

styling dropdownlist problem


Dear All,

im facing a problem while styling my ddl, what i did is:

<div><asp ropDownList ID="DropDownList1" runat="server" style="background-color:Transparent;" Width="100%">
    </asp: dropDownList></div>

<div class="stlGradient">
<asp ropDownList ID="DropDownList1" runat="server" style="background-color:Transparent;border:none;" Width="100%"></asp: dropDownList>

the DIV style is having a bg image repeated X.

now this worked on Firefox
on google Chrome: the border gone but the background still white
on IE 7: nothing happend

thanks for helping.

dropdownList CSS



Does anyone know what is the asp:dropdown's css is? I'm trying to make my ajax's comboBox to look the same as asp dropdown's css but I can't seem to find the default dropdown's css.

ASP.NetWindows Application  .NET Framework  C#  VB.Net  ADO.Net  
Sql Server  SharePoint  Silverlight  Others  All   

Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend