.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

can't insert from a dropdownlist within a detailsview

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

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

View Complete Post

More Related Resource Links

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"

2 questions - Dropdownlist from SQL Table and Insert into several tables

We're trying to convert an older access app with a sql server back end (with many tables) to Sharepoint. There are entry forms, update forms, look up forms, reports, etc the 2 questions I have are: 1. How can I create a dropdownlist that gets its items from a SQL table? 2. How can I create a form that, when filled out, puts items into multiple tables? Basically, I'd like to know if any of this is possible in 2010, and does anyone have any tips on where to start?    

DetailsView get key after insert

Hello!I'm trying to catch (in string "s") the primary key for the record being inserted via DetailsView. I have an SqlDataSource connection to an Access 2003 database. The primary key is auto-increment integer (long) field.Code:protected void SqlDataSource1_Inserting(object sender, SqlDataSourceCommandEventArgs e) { OleDbParameter insertedKey = new OleDbParameter("@KontaktID", OleDbType.Integer); insertedKey.Direction = ParameterDirection.Output; e.Command.Parameters.Add(insertedKey); } protected void SqlDataSource1_Inserted(object sender, SqlDataSourceStatusEventArgs e) { DbCommand command = e.Command; string s = command.Parameters["@KontaktID"].Value.ToString(); }generates an error:System.Data.OleDb.OleDbDataAdapter internal error: invalid parameter accessor: 12 BADBINDINFO.I can not figure out what I'm doing wrong??Thx in advance!

DropDownList inside FormView Insert Template

Hi, I am trying to change the textboxes in the FormView insert template to dropdownlists but they keep setting the parameters to null.   Here's what I have:  <asp:DropDownList ID="ddlYearOfQualification" SelectedValue='<%# Bind("YearOfQualification") %>' runat="server"> </asp:DropDownList> In Page_Load CType(frmSurvey.FindControl("ddlYearOfQualification"), DropDownList).Items.Add(New ListItem("2010", "2010"))CType(frmSurvey.FindControl("ddlYearOfQualification"), DropDownList).Items.Add(New ListItem("2009", "2009"))   and in the SqlDataSource InsertCommand="INSERT INTO [tblSurvey] (... [YearOfQualification] ...) VALUES ( ... @YearOfQualification ... ) And in insert parameters: <asp:Parameter Name="YearOfQualification" Type="Int16" /> And the insert fails with YearOfQualification as null. If I sue the standard textbox: <asp:TextBox ID="YearOfQualificationTextBox" runat="server"                 Text='<%# Bind("YearOfQualification") %>' /> It works.   Any ideas? Many thanks in advance.

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

Populate DropDownList in InsertItemTemplate after insert

I thought this one would be easy, but no go. What I am trying to do is the following: I have two DropDownLists in my InsertItemTemplate, each bound to its own datasource. After the fields in this form have been filled out and the ItemInserting event fires, I rebind the ListView to its datasource, but the DropDownLists turn out empty. I tried to bind them in the ItemInserting event and it seems they get filled, but nothing shows up in them when the page loads. I also tried to fill them in the ItemDataBound event, but the e.Item.ItemType == InsertItem doesn't do it. What is the solution?

Can I use a DetailsView control to insert and update with RIA services?



I'm struggling with trying to use RIA services from an ASP.NET web site.

I created a new web site, added an entity framework model, then added a RIA service that uses that model. I used the DomainDataSource control to bind the ASP.NET controls to the RIA service.

I have a GridView that shows items from the database (via RIA and the entity framework model underneath it), and can see the items fine. I added a DetailsView as a pop-up, as shown in http://mattberseth.com/blog/2007/07/modalpopupextender_example_for.html and http://mattberseth.com/blog/2008/04/masterdetail_with_the_gridview.html. When I click the "edit" link in a row in the GridView, the DetailsView shows with the right data, but clicking the "save" link doesn't actually update the database.

Furthermore, I can't work out how to add new items this way, as when I try and use the DetailsView to add a new item, nothing is sent to the database.

Anyone any ideas how this can be done?


DropDownLists inside Detailsview INSERT cant get to work.



I'm having a DetailsView which has two DropDownList's inside so I should be able to pick 2 values for the field from DDL instead of writing something for it. But I cant get it to Insert any new values to my Database...

Can anyone help me with this? I'm pasting my code and table details here below.

<asp:DetailsView ID="DetailsView1" runat="server" AutoGenerateRows="False"
        CellPadding="4" DataKeyNames="SignUpKey" DataSourceID="LinqDataSource1"
        DefaultMode="Insert" ForeColor="#333333" GridLines="None" Height="50px"
        Width="125px" oniteminserted="DetailsView1_ItemInserted"
        <FooterStyle BackColor="#5D7B9D" Font-Bold="True" ForeColor="White" />

Insert command not using selected value from DDL in a DetailsView


My web form contains a detailsview control that I have added a templated field to with a DropDownList in the InsertItemTemplate. The DetailsView default mode is 'insert. My detailsview is attached to a sqldatasource that has a stored procedure in the db to handle the insert. When I enter data in the fields and select insert all values from the detailsview are written to the table except for the selection that was made in the dropdownlist. I am using the ddl.selecteditem.value to populate my variable however when the insert method is envoked it doesn't send my value. The DDL value that I am capturing does not need to be written to the table it is just a flag for some variables that need to be set at the stored proc level. How do I get the DDL selected value to be sent with the insert statement? Any help would be greatly appreciated.

Here is my code behind:





Protected Sub

DropDownList1_SelectedIndexChanged(ByVal sender

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!

FindControl In DetailsView Edit & Insert ItemTemplate


Hey,guys. I got a problem about finding controls in Edit/Insert Itemtemplate inside a DetailsView.

Here is the code.

I put a Label (id= "Label6") to test whether the findcontrol method works or not. Unfortunately, I almost tried every means but still coudn't find it.

protected void Page_Load(object sender, EventArgs e)

  //Edit Button OnCommand
  protected void ButtonEditOnCommand(object sender, CommandEventArgs e)
  if (e.CommandName == "Edit")

  // Update Button OnCommand
  protected void ButtonUpdateOnCommand(object sender, CommandEventArgs e)
  if (e.CommandName == "Update")
  string sql = "UPDATE StudentInfo SET StudentName=@studentname, Score=@score, Grade=@grade, Remarks=@remarks WHERE ID=@id";
  SqlConnection conn = new SqlConnection(ConfigurationManager.ConnectionStrings["sqlconn"].ToString());
  SqlCommand cmd = new SqlCommand(sql, conn);

  // find controls
  if (DetailsView1.CurrentMode == DetailsViewMode.Edit)
  TextBox EditStudentName = (TextBox)DetailsView1.FindControl("TextBoxEditStudentName");
  TextBox EditScore = (TextBox)DetailsView1.FindControl("TextBoxEditScore");
  TextBox EditGrade

Detailsview insert


I have a detailsview in insert mode. I want to prompt the user to enter data in all fields, if left empty. Could someone please find a few minutes to show me how to do it?

Thanks in advance.

DetailsView - Cannot insert the value NULL into column


Can somebody tell me why I am getting this error when I try to insert data in a DetailsView 2.0? 

Cannot insert the value NULL into column 'Title', table 'C:\INETPUB\WWWROOT\TEST\APP_DATA\QUIZ.MDF.dbo.Question'; column does not allow nulls. INSERT fails.

I used the Configure Data Source wizard to set this up and Question ID is a autonumber.

When you autogenerate the Insert button on a Detailsview control and click on that button during run time the control posts back with text input areas where you are supposed to type the Title, Answer1, Answer2 etc. Obviously I typed data in to this text area labeled Title. It didn't work and that's why I'm asking about the control. Because I can't debug the control I am having a hard time figuring out where the problem is.

Here is the code and thanks for any help.

<asp:DetailsView ID="EditDetails" runat="server" Height="50px" Width="550px" AutoGenerateRows="False"  AutoGenerateInsertButton="True" AutoGenerateEditButton="True" AutoGenerateDeleteButton="True" CellPadding="4" DataSourceID="SqlDataSource1" ForeColor="#333333" GridLines="None" AllowPaging="True">
                        <FooterStyle BackColor="#5D7B9D" Font-Bol

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

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
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