Click here to Skip to main content
15,886,362 members
Everything / DropDownList

DropDownList

DropDownList

Great Reads

by Er. Puneet Goel
This tip implements the TreeView like DropDownList with Search Functionality using Telerik Kendo.
by Greg Barbados
This article provides a solution to add data validation to Excel cells in C#.
by Tadit Dash (ତଡିତ୍ କୁମାର ଦାଶ)
We will see one example of how to bind one DropDownList using jQuery Ajax and C# WebMethod.
by Tadit Dash (ତଡିତ୍ କୁମାର ଦାଶ)
Why DropDownList SelectedValue Does Not Work Inside SelectedIndexChanged Event?

Latest Articles

by Puja Jagani
Using jTable instead of drop-down list.
by Greg Barbados
This article provides a solution to add data validation to Excel cells in C#.
by cpsglauco
ASP.NET GridView – OnRowDataBound vs OnRowCreated
by Er. Puneet Goel
This tip implements the TreeView like DropDownList with Search Functionality using Telerik Kendo.

All Articles

Sort by Score

DropDownList 

9 Jan 2015 by Er. Puneet Goel
This tip implements the TreeView like DropDownList with Search Functionality using Telerik Kendo.
31 Mar 2016 by Greg Barbados
This article provides a solution to add data validation to Excel cells in C#.
14 Dec 2013 by Hammad
JavaScript $(document).ready(function () { $("#departmentList").change(function () { var dID= $(this).val(); $.getJSON("../Home/LoadPhysiansByDepartment", { deptId: dID }, function...
16 Apr 2014 by Tadit Dash (ତଡିତ୍ କୁମାର ଦାଶ)
We will see one example of how to bind one DropDownList using jQuery Ajax and C# WebMethod.
22 May 2014 by Tadit Dash (ତଡିତ୍ କୁମାର ଦାଶ)
Why DropDownList SelectedValue Does Not Work Inside SelectedIndexChanged Event?
19 Jul 2016 by Puja Jagani
Using jTable instead of drop-down list.
17 Sep 2013 by CodeBlack
You can create one method for dropdownlist binding and one method which gets data for dropdownlist as mentioned below : protected void Page_Load(object sender, EventArgs e) { if (!Page.IsPostBack) { this.BindData(); } ...
21 Oct 2013 by thatraja
Torakami wrote:But now what i want to do is i want to display only those categories in dropdowns which are surely give me the data It's not a big deal. Just load the data which matches the details table data.For example, you have two tables Country &...
30 Jan 2018 by Mohsin Mustufa
hii have two dropdownlist on a page i want that when i select some value from first dropdown list then in second dropdownlist all the values load according to the value selected both dropdown lists are binded dynamicallyViewFirst...
31 Jan 2014 by ZurdoDev
Make sure to test for !IsPostBack in the Page_Load event and only do your databinding when it is the initial load of the page.
14 Jun 2014 by Peter Leow
first the select query:select idorder, convert(varchar, ordernumber) + " (" + customername + ")" as orderno from order join customer on fk_customer = idcustomerthen the ddl:Data Text Field: orderno
5 Nov 2014 by DamithSL
if (dropdownlist.Items.Count
6 Jul 2017 by Richard Deeming
You need to pass the selected values to the MultiSelectList[^] constructor. It would also be more correct to use the ListBoxFor method, since you're not rendering a drop-down list. @Html.ListBoxFor(model => model.SelectedValues, new MultiSelectList(Models.GetCategoryList().OrderBy(c =>...
17 Jun 2019 by CHill60
This is simply achieved using VLOOKUP. For example in cell B2 of your empty sheet put the formula =VLOOKUP($A2,Workers!$A:$C, 2, 0) and in cell C2 of your empty sheet put the formula =VLOOKUP($A2,Workers!$A:$C, 3, 0) Note that it is better (quicker) to use INDEX and MATCH[^] if you have a lot...
11 Feb 2013 by _Maxxx_
If your UDF gives you back a table..Select xxx from Properties AS P join theUDFTable AS U on P.Area_Id = U.AreaID
21 Feb 2013 by Avik Ghosh22
http://csharpdotnetfreak.blogs...
21 Feb 2013 by giri001
Hi just i modified your code and make it according to your need...{ XmlDataSource oXmlDataSource = new XmlDataSource(); oXmlDataSource.XPath = "siteMap/siteMapNode"; XmlDocument doc = new XmlDocument(); doc.Load(Server.MapPath(".") +...
21 Feb 2013 by Harikamalina
http://r4r.co.in/asp.net/01/tutorial/asp.net/How%20to%20populate%20combobox%20from%20xml%20file%20using%20c-Sharp%20in%20asp.net.shtml[^]
23 Feb 2013 by Ranjith Reddy CSE
Hi Experts !!I have a dropdownlist in my aspx page.I want to take the data from database and place in this dropdownlist. whatever the data is in table it must display in dropdown.and when ever i add new item in table in should display in dropdownlist.Please can you help me, how...
23 Feb 2013 by Asim Mahmood
protected void Page_Load(object sender, EventArgs e) {If(!IsPostBack) BindDropDownList();}private void BindDropDownList(){ DataTable dtData = new DataTable(); dtData = //GetDataFromDb(); this.Ddl.DataSource = dtData; this.Ddl.DataValueField = "ID"; ...
4 Jun 2018 by arif_dzainal
Hi all,i have come confusion, how can we achieve this goalfor example, i have a dropdown, which the item is HR, Admin, ITeg : ...
21 Mar 2013 by vinodkumarnie
Try below..C# code below..protected void Page_Load(object sender, EventArgs e) { if (!this.IsPostBack) { if (DropDownList22.SelectedItem.Text == "IT") { Button1.CausesValidation = true; } else ...
13 May 2013 by Richard C Bishop
Here is a site that should get you started:Clickety click clack[^]
11 Jun 2013 by Zoltán Zörgő
If you don't want to do a postback on adding every and each hobby, you can either:- use a session variable to store the edited user's state and add the hobbies with an ajax call- use a multiselect listbox instead of dropdowns - use a "array" to keep the hobby list and post at once (see my...
26 Jul 2013 by _Amy
Refer the links below:Winform:AutoComplete Textbox[^]AutoComplete TextBox In WinForms Windows Forms Application[^]Asp.Net:ASP.Net AJAX Control Toolkit AutoCompleteExtender[^]Jquery Autocomplete Textbox With Asp.net Web Service[^]--Amit
14 Aug 2013 by basavrajmswami
Hi,You can checkout below code insted of database connection i created my own collection datasource.// School entity which will define structure of entity public class Schools { public int OfficeID { get; set; } public String OfficeName {...
15 Aug 2013 by Member 9549287
the loop doesn't do any actual sorting. a simple way to go by sorting lists of objects would be: ......{sortedlist} = {unsortedlist}.OrderBy(dc => dc.{columnOrattributevalueyouwanttosortby});//or you could use the same unsortedlist instead of creating a new...
16 Aug 2013 by timJosh
Declared outside:static List offices = new List { };Then added this:public class Schools { public int OfficeID { get; set; } public String Description { get; set; } }And finally:dtOffice = blSchoolT.loadSchoolAll(); foreach...
25 Aug 2013 by M.R.A.
Dim SqlAdp As SqlDataAdapter = New SqlDataAdapter("Select convert(datatime,dateofmonthly,101) from PaidDetails where SID='" & Me.txtRegNo.Text & "' and Statuspay='N' order by Nomonths", conn)for your required format yyyy-MM-dd you may change 101 to 100 or 102 like this
17 Sep 2013 by Harshil_Raval
Hi,Try this.protected void addemp_Click(object sender, EventArgs e){ DataTable empemails = new DataTable(); int srno = 1; empemails.Columns.Add("Sr.No"); empemails.Columns.Add("EmpName"); empemails.Columns.Add("Email"); foreach...
22 Sep 2013 by Jameel VM
Try this link.It help you to load dropdown and post selected id to action resulthttp://fromjami.wordpress.com/2013/09/17/loading-dropdownlist-in-asp-net-mvc/[^]Hope this helps
2 Oct 2013 by Azee
Hey there,I am not still sure about your problem, but here is what I think it is.You want the DropDownLists of the column have a selected value from the Datatype Column of the DataTable that the GridView is binding from.You can do two modifications and can make the selection this...
4 Dec 2013 by sazzad37
I have two drop down lists on my asp.net page, the second of which needs to be filled in based on the selection in the first dropdownlist. It's work fine when I set Autopostback="true". The catchhowever, is that it must occur without a postback/pageload.Does anyone have a way to accomplish...
2 Apr 2014 by Tadit Dash (ତଡିତ୍ କୁମାର ଦାଶ)
Try like below...var dropdown = document.getElementById('batchIDSelect');var opt = document.createElement('option');opt.innerHTML = ""dropdown.appendChild(opt);for (var i = 0; i
2 Apr 2014 by Sanjay K. Gupta
You can insert a blank item at position 0function GetDisplayBatchID() { debugger; $.ajax({ url: 'QCAllocation.aspx/GetDisplayBatchID', type: 'POST', contentType: 'application/json; charset=utf-8', dataType: "json", success: function...
3 Jun 2014 by norbitrial
Use backslash before double quotes and it will work properly:"
3 Jun 2014 by Nirav Prabtani
see this.. :)DropDownList in Repeater[^]How to bind a DropDownList from inside a Repeater ?[^]RESOLVED-Data-bind-DropDownList-inside-a-repeater-contol[^]
14 Jun 2014 by Debabrata_Das
Hello friend, to achieve that you have to create a field concatenating two columns as per your need at the SQL level as follows:SELECT O.idOrder, O.OrderNumber + '(' + C.CustomerName + ')' AS Order_CustomerFROM TableCustomer C INNER JOIN TableOrder O ON C.idCustomer = O.fk_CustomerThen you...
30 Jun 2014 by Tadit Dash (ତଡିତ୍ କୁମାର ଦାଶ)
So, you have to again query your database and fetch all the categories except the ones related to the current Product.After getting those, just bind that to the DropDownList.
24 Jul 2014 by Yogesh Kumar Tyagi
view this article it may help youhttp://www.c-sharpcorner.com/UploadFile/3d39b4/casecading-dropdown-list-with-mvc-linq-to-sql-and-ajax/[^]
25 Aug 2014 by _Amy
Bind your DropDown in !Page.IsPostBack property.private void Page_Load(){ if (!IsPostBack) { // Bind dropdwon here.. }}--Amy
17 Sep 2014 by Richard Deeming
You'll get better results if you bind the list in the Init event of the control, rather than the page.protected void ddlCustomers_Init(object sender, EventArgs e){ var ddl = (DropDownList)sender; ddl.DataSource = SystemData.GetAllCustomers(); ddl.DataTextField =...
19 Feb 2015 by Praveen Tiwari
set the following properties for comboboxcomboBox1.AutoCompleteMode = AutoCompleteMode.SuggestAppend;comboBox1.AutoCompleteSource = AutoCompleteSource.ListItems;
22 Feb 2015 by RajeeshMenoth
In ur ddl code add this one : ddlcountry.Items.Insert(0, "-Select-");
24 Feb 2015 by Tadit Dash (ତଡିତ୍ କୁମାର ଦାଶ)
Don't make this complicated. There is a very easy way of doing this using Ajax CascadingDropDown.Refer - AJAX Cascading DropDown Example in ASP.Net[^]
1 Jun 2015 by Member 10392328
Thanks for your responses. I figured out the actual problem and able to done it in simple step. First, I make the AppendDataBoundItems behavior of my drop-down list To TRUE and kept the following code and it works perfectly. protected void Page_Load(object sender, EventArgs e) { ...
17 Jun 2015 by Richard Deeming
Assuming your DetailsView has its DataSourceID property set to "SqlDataSource1", you don't need to handle the ItemInserting event in the code-behind. The statements will automatically pass the selected values to the parameters on the data-source control.EDIT: Try moving...
23 Jun 2015 by Philippe Mori
Forget that. It make no sense to mimic old behavior on new browser. How other browser like Edge, Safari, Firefox, Chrome works? I don't thing that those details are defined and if so, then the new behavior would surely be the right one.By the way, the old IE way is a bad design. Why...
14 Jul 2015 by Hector Menchaca
Hello,Maybe at the moment of doing the render of your page you are not using the List class..I found this article and I think it can helps.http://stackoverflow.com/questions/27378288/but-this-dictionary-requires-a-model-item-of-type-system-collections-generic-ie[^]Best Regards!
22 Jul 2015 by OriginalGriff
Use DateTime.ParseExact: DateTime dtStart = DateTime.ParseExact("12:00 AM", "hh:mm tt", CultureInfo.InvariantCulture); DateTime dtEnd = DateTime.ParseExact("10:00 PM", "hh:mm tt", CultureInfo.InvariantCulture);Replace the constant times with your drop down values, and...
15 Oct 2015 by Krunal Rohit
By using css..ddl{ width: 20%; height:10%; /*width - height whatever you want*/}
27 Apr 2016 by Sergey Alexandrovich Kryukov
Please see my comment to the question.The first bug I can see is using val. It means that you try to set the value of the value property of the element option. You certainly can do it, but this property has no significance to this element, in terms of visible HTML DOM. It can be used to pass...
4 Jul 2016 by Suvendu Shekhar Giri
As the error message suggests,You need to have an element in the dropdown which has value same as the value you are assigning to in the Selectedvalue property.ddlLocn.SelectedValue= dt.Rows[0]["LocName"].ToString();Here, your dropdownlist need to have a element with value which is equals...
4 Jul 2016 by Karthik_Mahalingam
Try this string locationName = dt.Rows[0]["LocName"].ToString(); ListItem targetItem = ddlLocn.Items.FindByText(locationName); if (targetItem != null) targetItem.Selected = true;if the above doesnt work, try with FindByValue [^]
20 Jul 2016 by F-ES Sitecore
There are no native controls to do that but if you google "jquery drop tree" you'll probably find some plug-ins other people have written.Live Demo - jQuery EasyUI[^]Giva Labs - mcDropdown jQuery Plug-in | Giva[^]
31 Jul 2016 by Tadit Dash (ତଡିତ୍ କୁମାର ଦାଶ)
Change if (Page.IsPostBack) to if (!Page.IsPostBack).
4 Nov 2016 by pparya27
Here is a sample code for your requirement, you can modify it as per your requirement -
26 Jan 2017 by F-ES Sitecore
That's how dropdowns work, there are two elements, the name and the value. The name is what appears in the list and the value is what is submitted with the form. Normally you'd convert the ID back to the relevant text when needed. However if you really do only want the text and you don't care...
19 Feb 2017 by Graeme_Grant
Here is a good place to start looking: Telerik Kendo ComboBox samples[^] and a good place to ask questions is: Telerik Forums[^]
15 Mar 2017 by Sunasara Imdadhusen
Hi,You can change the id of dropdown to "P_CatedoryID"from@Html.DropDownList("Categories", (SelectList)ViewBag.RequiredKey, new { @class = "form-control" })to@Html.DropDownList("P_CatedoryID", (SelectList)ViewBag.RequiredKey, new { @class = "form-control" })
6 Aug 2020 by Kasthuri Gunabalasingam
I need a way to set already selected values in a multi select dropdown in a edit view in a web application (ASP.NET, Mvc) from view code,I passed selected ids in to selected values array.(when I return values from DB , assign those in to a array then assign to here. I need a edit view by set...
19 Sep 2017 by OriginalGriff
Most likely, it's that you are converting a value to a string: if it's a number like 54, then ToString will convert it to "54" - which is not the same value as the "054" you are comparing against. So start with the debugger, and find out exactly what the value in capturemethodtoeci actually is...
27 Sep 2017 by Karthik_Mahalingam
use SelectedValue [^], DropdownList doesnt have a property called Value Select1.SelectedValue;
7 Dec 2017 by Dave Kreskowiak
You simply do NOT put that much data into a control, EVER. Using a dropdown to show a hundred thousand records is a really bad idea. That's not the control for the job. The only way to show that much data is paging, showing only the number of records that will fit in the display. This is...
27 Apr 2018 by Dhaval_Nayi
This worked for me: DropDownList1.Items.FindByText("Value").Enabled = false; you can try this also: DropDownList1.Items[/*index*/].Enabled = false;
16 Dec 2018 by Vincent Maverick Durano
First off, if you are pre-selecting values at SelectedIndexChanged event of DropDownList, then you need to set AutoPostback to TRUE to trigger the SelectedIndexChanged event. Second, if you are binding and doing the pre-selection at Page_Load event, then make sure you wrap your code within...
9 Dec 2019 by Maciej Los
Please, read my comment to the question first! Here is an example of what i've stated in the comment. System.Globalization.CultureInfo[] cis = new System.Globalization.CultureInfo[] { new System.Globalization.CultureInfo("PL-pl"), new System.Globalization.CultureInfo("DE-de"), new...
18 Dec 2012 by AhmedOsamaMoh
dear siri am using asp.net FORMS Vs2010 + MySqli have a dropdownlist binded to a datasoure ( username , password , user rank), i display the username and i return the password in selected value and the dropdownlist sorted by rank the problem the dropdownlist lose the selected item and...
28 Dec 2012 by Software Engineer 892
Dear Friends,How to redirect Pages Based on Dropdownlist in Asp.Net c#?I have 3 webpages in my project, when i select one page from dropdownlist. it should redirect to that page and that page should be displayed.My pages are :1)AttendanceReports.aspx 2)Exam...
28 Dec 2012 by Zoltán Zörgő
Select report!Attendance ReportExam ReportOther...
14 Jan 2013 by Ben Matheson
HelloI have a Drop Down List in a web page, what it currently does is displays an individual image that is selected in the list.Please find my code below.What I want to achieve is if a sector is selected such as pubs for example, It will display a group of images of pubs instead of...
19 Jan 2013 by vinodkumarnie
If you want display group of images to shown on selection of dropdownlist you should create images dynamically by assigning related image path.. university
19 Jan 2013 by Nasser Abu Farah
HiI have a web Form with one DropDownList which read it's data from a table.and I have a button next to the DropDownList which run's an insert query to add a new item to the table.Until now every thing is fine, but what I need now is to refresh the DropDownList and automatically select...
20 Jan 2013 by chenthil28
Before insert the data to the database table, store the value in some variablefor ex. Dim strNewValue$="New Data"InsertDatabase("New Data") 'Ur functionality to insert in databaseDim dt as datatable = drpYourdropdown.datasourceDim dr as...
23 Jan 2013 by Member 9581488
Please refer below link. I hope that helps.http://stackoverflow.com/questions/10517741/conversion-failed-when-converting-datetime-from-character-string-in-store-proced[^]
23 Jan 2013 by sr_24
c# code --Dropdown codeprivate void FillBatch() // Batch { try { clsDataAccess da = new clsDataAccess(); da.AddTabletoDataset("SELECT Batch_Year,BatchId FROM Batch", "Batch"); if (da.DataSet.Tables["Batch"].Rows.Count > 0) ...
23 Jan 2013 by AdityaPratapSingh
try this-private void FillBatch() // Batch { try { SqlDataAdapter da=new SqlDataAdapter("SELECT Batch_Year,BatchId FROM Batch", con); Dataset ds=new Dataset();da.Fill(ds); if (ds.Tables[0].Rows.Count > 0) { ...
23 Jan 2013 by AshishChaudha
try below code protected void BindCountryDropDown() { DataTable dt = null; using (conn = new SqlConnection(ConfigurationManager.ConnectionStrings["tempdbConn"].ConnectionString)) { using (SqlCommand cmd = conn.CreateCommand()) { ...
23 Jan 2013 by syeda jenna
Plz help meDropdownlist is populating by linq on load event it has two fields (Id- for value) and (Name-for text).in event of dropdown selectection selected value without post back get address field too from db table as already queried for dropdown list population) and set on textbox.
30 Jan 2013 by gouravkaila
Dear All,I want to populate a dropdownlist on the selected index changed of the other dropdownlist without postback.Could you please tell me how to do that using jquery as if i use traditional Ajax to call the code behind of same page,i will have to go through page_load event also...
30 Jan 2013 by Ankur\m/
Check out this article - Using jQuery to directly call ASP.NET AJAX page methods[^].I remember reading this while first implementing the scenario you mentioned. It's neat and simple.There are many other on the web - calling asp.net server side code using jquery[^]Hope this helps!
2 Dec 2016 by rrjoshi2321992
I m populating subcategory dropdown fom category dropdown.but when i change category in category dropdown its "SelectedIndexChanged"event is not firing.here is my code:-Markup:-
6 Feb 2013 by Shanmugam Rathakrishnan
Hi all, i am new to ASP .NET and Particularly in ASP .Net MVC3 Razor...i have created view for Clients and Executives in MVC3 Razor.What i did is 1st i created Model called Clients.cs namespace MVCInetClient.Models{ [Table("tbl_Customer")] public class Clients { ...
7 Feb 2013 by Jameel VM
Create a class ClientViewModel and reuse all the properties in Client class also add a additional property ExecutiveId.Create Client View on the basis of this viewmodel class then follow the below steps. The best practice is to keep the database entity separate and create a separate...
7 Feb 2013 by Shanmugam Rathakrishnan
In the Model... i added one more property, that is, public virtual IEnumerable ExecutivesList { get; set; } In the Controller... // GET: /Clients/Create public ActionResult Create() { // The Code i Added... Clients model = new...
10 Feb 2013 by Jameel VM
Try like thisAdd a common class for DropDownList like belowpublic static class DropDownList { public static SelectList LoadItems(IList collection, string value, string text) { return new SelectList(collection, value, text); } }Call the...
11 Feb 2013 by jhoward73
I am trying to construct a sort of "Property Search" Query for my site.Where I am so far: I have a multi select dropdownlist on my site that contains "Neighborhoods" within a city. I am passing the selected IDs of that dropdown to a stored proc via a comma delimited list (varchar). I am...
14 Feb 2013 by jiji2663
i cant bind data to dropdownlist in gridview from code behind without sqldatasourcemy code is:protected void Page_Load(object sender, EventArgs e) { if(!IsPostBack) GetData(); } public void GetData() { DataTable dt = new DataTable();...
14 Feb 2013 by charukannan
Add the dropdownList value at GridView1_RowDataBound event.1. Add the grvDC_RowDataBound event to page2. Get the dropdownlist value in dataset at pageload. and declare the DataTable 'dt_pursuit' as common to all function3. In grvDC_RowDataBound event add the dataset value to...
14 Feb 2013 by Jegan Thiyagesan
Hi Have you tried something like this. ((DropDownList)GridView1.Rows[e.RowIndex].FindControl("DDLpursuit")).DataSource = dt_pursuit.Rows.AsQueryable().OfType().ToList();I am not sure whether will work but could be worth a try.RegardsJegan
15 Feb 2013 by Jegan Thiyagesan
HiActually answer is here:bind data to dropdownlist with c#[^]RegardsJegan
21 Feb 2013 by MAU787
HI all,i have this xml document HO Admin 1 Circle Admin 2 Branch Admin ...
23 Feb 2013 by Bassofa
Several ways to do this:you can write sql command that pull the data from the database asSqlCommand cmd = new SqlCommand("Select Value1,Value2 from table");And then specify the datasource of your dropdownlist as follows:dropdownlist1.datasource()...
23 Feb 2013 by Abhishek Pant
Binding DropDownList With Database in ASP.NET[^]Ajax Cascading Dropdownlist Sample with database using asp.net [^]google[^]
8 Mar 2013 by dedo1991
Dear programming community,I am trying to populate the dropdown list by calling a method from the controller.The reason why i am doing this is because i want to pass it an id and therefore ill be getting a different list for each record.Viewgrid.Column(header: "Wards", format:...
8 Mar 2013 by venumailorg
You have to return the result in JSON format from controller. Then at the client side use JQuery to populate the values in the dropdown list using the JSON resultset.
12 Mar 2013 by Rupesh Kumar Tiwari
You can declare cursor property like below: $( "#draggable" ).draggable({ cursor: "move", cursorAt: { top: 56, left: 56 } }); see more onhttp://jqueryui.com/draggable/#cursor-style[^]
20 Mar 2013 by Prasad Khandekar
Hello,In your server side page load handler check the value of dropdown and if it anything other than IT then set CausesValidation property of the TextBox32 to false. You can also set Enabled property of chkDateReturn to false.regards,