.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

bind values to dropdownlist using ASP.NET MVC

Posted By:      Posted Date: August 25, 2010    Points: 0   Category :ASP.Net


I'm using asp.net MVC 2.0, my controller coding is,

foreach(DataColumn dc in dtImport.Columns)


TempData["drpsku"] = dc.ColumnName.ToString();


i need to bind this value to the drpdown list in the aspx page.

<asp:DropDownList ID="DropDownList1" runat="server"></asp

View Complete Post

More Related Resource Links

how to bind Dropdownlist based on textbox values



I have one drodownlist which show data based om textbox values...

Let us consider i have 

Select Name from table1 where Type IN(@typ)

here @typ is textbox values

here for example textbox will have some thing like this L1,L2,L3..

How to filter Name based and shown in drodownlist based on this L1,L2,L3(on textbox)..

Help me in this

How to bind distinct values to DropDownList from DataSet (as a result of a web service call)?


Hi there,

I'm trying to bind a dataset (where the data is coming from a webservice) to a dropdownlist; the problem is that I'm getting duplicates in the list... how can I display distinct values only:

drp_Brand.DataSource = ds.Tables[0];
            drp_Brand.DataTextField = "Brand";
            drp_Brand.DataValueField = "Brand";



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

DropDownList to display values from Two Tables - bold sub heading and normal Text

Hello I hope I am not asking simple one.  SUPPORT SERVICES<     Computing Service    Library or Data Engineering    Civil Engineering    Electrical Engineering  I have the data to display in a DropDownList control shown as above. There is a distinct category Type(example Support Services) and Category Name i.e., Computing Services. I do not want to hard code the values into DropDownList control. I like to get the data from database to display as shown in above Table. Note that Category Type should be displayed in Bold and Category Name in normal Text. Question: In order to achieve the above, 1. How many database Tables and relationships between them  2. Query the data to display in the above format in drop down 3. how should be the code behind i.e, DataTextValue and DataValueField for DropDownList. Please provide with useful code snippets or references. Thanks,

Accessing a row's dropdownlist values AFTER the gridview control is in Edit mode

Hello, I have a gridview control. When it goes into Edit mode, there are 3 dropdownlists in one cell that are populated by separate stored procedures during the RowDataBound event. The 1st dropdownlist's value is used as a parameter to determine what the 2nd dropdownlist is populated with. The 2nd dropdownlist's value is used as a parameter to determine what the 3rd dropdownlist is populated with. Everything works fine when the row is first put into Edit mode. While I'm in Edit mode and I change the selection in the 1st dropdownlist, how do I access the control so I can feed this new parameter to the 2nd dropdownlist? I have the first 2 dropdownlists set for AutoPostBack so that the Page_Load event is fired when the user changes a value. I know how to get access to these controls via the FindControl method when the row is being databound but how do I find the control during the Page_Load event? Thanks for any help!!!   Penny  

bind values for the drop down based on people picker value change

hi, i have a two lists in my sp. list 1 name  items user1 item1 user1 item2 user2 item1   and list 2 is in this way in this i have a people picker and a drop down when ever i change the name in people picker the value should get filled from list 1 and fill in drop down list so i need to get the on text changed event of people picker and bind it in the dropdown list could some help me out in fixing thisjayaraja

bind values for the drop down based on people picker value change

hi, i have a two lists in my sp. list 1 name  items user1 item1 user1 item2 user2 item1   and list 2 is in this way in this i have a people picker and a drop down when ever i change the name in people picker the value should get filled from list 1 and fill in drop down list so i need to get the on text changed event of people picker and bind it in the dropdown list could some help me out in fixing thisjayaraja

How to bind a List of hybriddictionay to the dropdownlist

I have a List<HybridDictionary> _Reasons.I need to bind the list to a dropdown. I tried the code as try            {                this.ddlReason.DataSource = _Reasons;                ddlReason.DataValueField = "Key";                ddlReason.DataTextField = "Value";                this.ddlReason.DataBind();                           }            catch            {                //Log Entry            }            finally            {             } But it not work.Please sugges

How to bind GroupBy Values in Nested Repater Control


In a dataset i m getting values like this

IdApplication    ApplicationDesc    Permissions

1                       User                      Add

1                       User                      Delete

1                       User                      Update

2                       Role                       Add

2                      Role&n

cannot bind dropdownlist inside from button click inside updatepanel



I have a gridview inside UpdatePanel. 

Inside gridview there is a dropdownlist and a button on each row. On button click I am opening a panel through Modal popup extneder.

Inside that pop up there is again a dropdownlist. I am adding an item into this dropdownlist based on the selection from the dropdown inside gridview. 

like  ddl.items.insert(0,'xyz');

But first time this inserted item is not getting reflected in the dropdownlist. But after one postback this item is getting reflected.

Please let me know how to fix this. I tried UpdateMode conditional and always but didn't worked. If I am not clear let me know.


Create a year dropdownlist that with dynamically created year values


Using vb.net/asp.net 2005

I have a Year dropdownlist that I want to have the listItems created dynamically with these conditions:

1.  the oldest year selection will be "2009"

2.  all years including "2009" and the current year will be included in the listitems.

It's obvious now (at this date) that 2009 and 2010 will be the 2 current listitems, however I want this dropdownlist to automatically add all subsequent years in coming years so that there will not be the need to add a new year listitem each year.



How to get list of VALUES (not items) from a dropdownlist?


Hello all.  I see that dropdownlist has an "items" property to get the list of displayed items for a dropdown, but it doesn't seem to have an equivalent property for getting the "values" associated with the items.  For example, I may have a dropdown that displays "High", "Medium" and "Low", but returns values of "H", "M", "L".  How can I easily get that list of HML?

Thanks for any help!


Pasing Values from 1 dropdownlist to another in detailsview


Hi Guys. I have a problem I have been googling the entire day and still have no soloution. I have a detailsview with 2 dropdownlists. Fisrt one is ddlCaregory. Second is ddlSubCategory. The value is passed from the first ddl to display the SubCategory linked to ddlCategory. Both ddlCategory and ddlSubCategory are Templatefields. This is also in VB.

The Details view has a sqlDataSource (sdsApplicants), ddlCategory has a Datasource (sdsCategory) and ddlSubCategory (sdsSubCategory). ddlCategories lists the data returned from sds Categories and save any changes to sdsApplicants. I can get ddlSubCat to display the correct SubCatagory bases on ddlcategory sesection but as soon as I try bind it to sdsApplicants I get the following error

'ddlSubCategory' has a SelectedValue which is invalid because it does not exist in the list of items.
Parameter name: value

I will be so greatfull if someone could help me find the soloution to my problem!

Bind dropdownlist to enum


I want to bind the value and the name of the enum to the dropdownlist.  I've been looking around about how to do this, and found some examples, but it's not working for me for some reason:



public enum Salutations
    Mr = 1,
    Ms = 2, 
    Mrs = 3

string[] names = Enum.GetNames(typeof(Salutations));
Array values = Enum.GetValues(typeof(Salutations));
for(int i=0; inew ListItem(names[i], values[i].ToString());

The problem is trying to access the value in values.  I can't do it for an Array.  How can I modify this?




Carrying on DropDownList selected (values/indexes ) among "Insert" operations of the same kind


I have struggled trying to find a way of making current values selected from all dropdownlist that I might have available inside an Insert page [for any table that I could be working on]... [of course the amount of dropdownlist boxes displayed vary with each table depending on the database schema and referential integrity].

Could be possible that anyone had developed an standard control or a piece of code that can do this as to "carry on" previously dropdownlist selected values so they can be used again and make the UI more friendly because as it is now Dynamic Data resets all values and takes you back every single time you make an Insert operation? I guess Microsoft's Dynamic Data Team working on it ... shouldn't they?

Suppose that you are working entering data for a "products" catalog and you have to introduce 20 items of the same kind. You wouldn't be supposed to be selecting values from the same dropdownlists 20 different times if you had available previously selected values which will make your job easier.

I have tried successfully building a matrix which accomplishes this but I have faced the problem that when it comes to "composite keys" my solution doesn't work because I should have available the SelectedIndex instead of the SelectedValue that Dynamic Data uses by

jquery ajax - bind json to dropdownlist


I'm using jquery ajax to populate a dropdown list to avoid page refresh via a webmethod.

My webmethod returns a json string. My question is how can i bind this to my asp.net dropdownlist?

See below for jquery code:

function getTeamid() {
        var teamid = $(".ccTeam").val();            
            type: "POST",
            url: "NewJob.aspx/sayHello",
            data: "{val:" + teamid + "}",
            contentType: "application/json; charset=utf-8",
            dataType: "json",
            success: function(msg) {
                error: AjaxFailed


    function AjaxSucceeded(result) {
    function AjaxFailed(result) {
          alert(result.status + ' ' + result.statusText);

See below for webmethod code:

        public static string sayHello(string val)
            DataTable dt = dbTeam.getJobTypesByTeamid(val);
            return Intranet.Core.Util.GetJSONString(dt);            


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