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

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

Pasing Values from 1 dropdownlist to another in detailsview

Posted By:      Posted Date: October 11, 2010    Points: 0   Category :ASP.Net

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!

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

bind values to dropdownlist using ASP.NET MVC



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

Weird problem in Detailsview - Dropdownlist in



I'm new in this forum and I really hope you'll be able to help me.

I converted a field in the detailsview into a template field and put a dropdownlist in the <InsertItemTemplate> and it worked great. This is the code I put:

<InsertItemTemplate><asp:DropDownList runat="server" DataSourceID="sdsGenresPossible" DataTextField="Genre"  DataValueField="Index" SelectedValue='<%# Bind("Genre") %>' ></asp:DropDownList></InsertItemTemplate>

Now, I tried to do the same thing for the <EditItemTemplate> . This is the code I put there:

<EditItemTemplate><asp:DropDownList runat="server" DataSourceID="sdsGenresPossible" DataTextField="Genre" DataValueField="Index" SelectedValue='<%# Bind("Genre") %>' ></asp:DropDownList></EditItemTemplate>  

When I change the DV properties I do see that a dropdownlist was  added but when I run the program and click on "Edit" in the DV nothing happens (however when I click on "Insert" it works fine).

This is the Select command for the data source I used:

<asp:SqlDataSource runat="server"

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  

Problem binding data to DropDownList in DetailsView

Hi guys. I have a slight issue I awas trying to fix for 2-3 days, but nothing I try works. The scenario: DetailsView control in edit mode, I pass parameters to the SqlDataSourceProducts (edit.aspx?id=2) and the data source selects the appropriate data and fills in the DetailsView form. Except two drop down lists. These two DDLs (DDL2 and DDL3) are dependent on the previous DDL (DDL1) in the DetailsView. Thanks to PeteNet, when the selected value of the DDL1 changes, DDL2 and 3 change their lists and get bound to the database. The problem is: when I edit something from the database, DDL2 and 3 appear empty and when I update any other field and leave these, they get blanked in the database.  My goal is to set the selected value of DDL2 and 3 to the values in the database WHERE ID = QueryStringField="id". I can go for not binding the data unless the field is changed, but does not sound professional and user friendly. code: The SqlDataSource used to select the parameters from the table and populate the DetailsView <asp:SqlDataSource ID="SqlDataSourceProduct" runat="server" ConnectionString="<%$ ConnectionStrings:ConnectionString %>" SelectCommand="SELECT ID, wm_number, upc, check_digit, unit, price_unit, brand, category, shelves, type, cooking, storage, packaging, origin, nutriti

DetailsView ItemCommand CommandName Values


The DetailsView control has in its Events an ItemCommand event that uses the DetailsViewCommandEventArgs event arg class which has a CommandName property.

My questions are...

  1. What are the possible values (e.g. "Select", "Insert", etc.) for this CommandName property when operating a standard, uncustomized DetailsView control?
  2. Which order do the following fire in?
    1. ItemCommand
    2. ItemCreated
    3. ItemDeleted
    4. 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 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 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!


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

DetailsView Get Values on Insert. Major Problem :(



I'm having a problem to get the inserted values from the detailsview. I've tried the following things:

           // Get Value from DropDown
        int TopicID = 0;
        foreach (DetailsViewRow row in ItemsDetailsView.Rows)
            if (row.Cells[0].Text == "Topic")
                 DropDownList TopicDropDown = (DropDownList)row.Cells[1].FindControl("Topic_TopicIDList");
                 TopicID = int.Parse(TopicDropDown.SelectedValue.ToString());


            MsgBox(CType(DetailsView1.Rows(1).Cells(0).Controls(0), Label))

            For Each row As DetailsViewRow In DetailsView1.Rows

                Dim cell1 As TableCell = row.Cells(1)

                Dim value1 As String

                value1 = cell1.Text



            Dim item As New DetailsViewItem(col.ColumnName, row(index).ToString(), col.DataType.ToString(), col.DefaultValue)


            tb = DetailsView1.FindControl("Categorie")
            s = tb.Text


            For Each dvr As DetailsViewRow In DetailsView1.Rows
                If dvr.Cells.Count = 2 Th

can't insert from a dropdownlist within a detailsview


OK, I figure that this should be relatively straightforward, but I still can't get it to work. I have a gridview and a detailsview to set up shifts for students and teachers. I would like to be able to insert new shifts using a detailsview. I will limit the students, teachers and location to items that are in a dropdownlist. 

The problem is that when I handle the iteminserting event. the e.values collection doesn't contain all of the fields I want to populate. How do I add the new fields to the list. 

This is my codebehind:

    Sub On_Inserting(ByVal sender As Object, ByVal e As DetailsViewInsertEventArgs)
        e.Values("student") = tbStudent.SelectedValue
        e.Values("shift_location") = CType(dvNewShift.FindControl("newlocation"), DropDownList).SelectedValue

How To Do Country-State DropDownList Dependency in DetailsView Control


I have a DetailsView control in my C#/ASP.NET web application. It contains many fields, but the two I'm interested in are the Country and State fields. They are dropdownlists that display the information from the Country & State tables in the database. However, I want the State list to be filtered based on the selected Country.

I've seen many, many examples of this where the dropdownlists are outside of the detailsview controls. What I need to know is how to get it to work when these are inside of the detailsview control. I have moved the EntityDataSources for each dropdownlist outside of the detailsview control since I know that due to scope they wouldn't be able to see each other otherwise.

So, how do I make it so that when you select a country from the country dropdownlist, it auto-filters the state dropdownlist to only show the states in that country? This end of this video on ASP.NET explains how to do this outside of a DetailsView control, but not inside.


P.S. - I am using the Entity Framework / Entity Data Source for my data sources for everything.

DropDownList in DetailsView, invalid SelectedValue


I believe my question is not new here, but I think it is valuable because there are so many results from google with the 'dropdownlist in detailsview' as keywords.

Well, my question is described as below. (ASP.net and C#)

1)  I need a detailsview to add and edit record of table T1, which contains products information. T1 has a field 'catalog' which indicates the catalog of the product. All possible catalogs is stored in table T2. The simplified tables is described in 2)

2)  Simplified tables:

  • T1 fields: id, prodname,  catalog;  which is the datasource of the DetailsView.
  • T2 fields: id, catalog; which is the datasource of the dropdownlist in the detailsview.
  • all record of T1 have a catalog, which is picked up from T2.

3)  Functions I need are:

  • when detailsview in edit mode and insert mode, the field catalog should turns from a textbox to a dropdownlist which contains the catalogs stored in T2 .
  • when the item(catalog) of dropdownlist is selected and the 'update' button is clicked, the selected catalog (from T2) should replace the exist one of T1.

4)  My procedures to achieve the functions were:

  • drag and drop a detailsview control to a page, bind a datasource to it, en

Dropdownlist values with quotes


I have a dropdownlist which gets the data from the oracle database, the values that contains quotes example "Apple's" or "Website's" or not getting seelcted from the list except these values remaining values have no issues. Please let me know your suggestions.

Two DropDownList on one DetailsView



I have a details view which works without any problems:

<asp:detailsview id="detailsview1" runat="server" height="50px" width="550px" CellPadding="2" 
                         datakeynames="ZavPogodbaID" datasourceid="SqlDataSource1" 
                         fieldheaderstyle-width="115px" autogeneraterows="false" DefaultMode="Insert" 
            <FieldHeaderStyle Width="150px" />
                <asp:TemplateField HeaderText="Stranka:" ControlStyle-Width="400px" ControlStyle-Font-Bold="true" >
                        <asp:DropDownList ID="ddlStranka" Enabled="false" runat="server" DataSourceID="SqlDataSource3" 
                                            DataTextField="strSkrajsanNaziv" DataValueField="StrankaID" SelectedValue='<%# Bind("StrankaID") %>'>
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