DropDown list submits first value not the selected value

I am relatively new to programming and am having a problem with a small project that I am working on.  I have a names drop down list that is created from a database.  When the user selects a name and completes the rest of the form and clicks submit.  All of the data they entered is submitted to a different table in that database.  This is workign correctly for all of the data except the drop down.  For some reason the first value in the drop down is being submitted each time.  Here is the code and any help you can give will be appreciated.

Public Class final1

Inherits System.Web.UI.Page

#Region " Web Form Designer Generated Code "

'This call is required by the Web Form Designer.

<System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()

Me.SqlConnection1 = New System.Data.SqlClient.SqlConnection

Me.SqlDataAdapter1 = New System.Data.SqlClient.SqlDataAdapter

Me.SqlInsertCommand1 = New System.Data.SqlClient.SqlCommand

Me.SqlSelectCommand1 = New System.Data.SqlClient.SqlCommand

Me.SqlDataAdapter2 = New System.Data.SqlClient.SqlDataAdapter

Me.SqlInsertCommand2 = New System.Data.SqlClient.SqlCommand

Me.SqlSelectCommand2 = New System.Data.SqlClient.SqlCommand

Me.DataSet11 = New norfolkcasereview.DataSet1

Me.SqlDataAdapter3 = New System.Data.SqlClient.SqlDataAdapter

Me.SqlInsertCommand3 = New System.Data.SqlClient.SqlCommand

Me.SqlSelectCommand3 = New System.Data.SqlClient.SqlCommand

CType(Me.DataSet11, System.ComponentModel.ISupportInitialize).BeginInit()




Me.SqlConnection1.ConnectionString = '



Me.SqlDataAdapter1.InsertCommand = Me.SqlInsertCommand1

Me.SqlDataAdapter1.SelectCommand = Me.SqlSelectCommand1

Me.SqlDataAdapter1.TableMappings.AddRange(New System.Data.Common.DataTableMapping() {New System.Data.Common.DataTableMapping("Table", "suspo", New System.Data.Common.DataColumnMapping() {New System.Data.Common.DataColumnMapping("SUSPO", "SUSPO")})})




Me.SqlInsertCommand1.CommandText = "INSERT INTO dbo.suspo(SUSPO) VALUES (@SUSPO); SELECT SUSPO FROM dbo.suspo ORDER B" & _


Me.SqlInsertCommand1.Connection = Me.SqlConnection1

Me.SqlInsertCommand1.Parameters.Add(New System.Data.SqlClient.SqlParameter("@SUSPO", System.Data.SqlDbType.VarChar, 30, "SUSPO"))




Me.SqlSelectCommand1.CommandText = "SELECT SUSPO FROM dbo.suspo ORDER BY SUSPO"

Me.SqlSelectCommand1.Connection = Me.SqlConnection1




Me.SqlDataAdapter2.InsertCommand = Me.SqlInsertCommand2

Me.SqlDataAdapter2.SelectCommand = Me.SqlSelectCommand2

Me.SqlDataAdapter2.TableMappings.AddRange(New System.Data.Common.DataTableMapping() {New System.Data.Common.DataTableMapping("Table", "officer", New System.Data.Common.DataColumnMapping() {New System.Data.Common.DataColumnMapping("uspo", "uspo")})})




Me.SqlInsertCommand2.CommandText = "INSERT INTO dbo.officer(uspo) VALUES (@uspo); SELECT uspo FROM dbo.officer ORDER " & _

"BY uspo"

Me.SqlInsertCommand2.Connection = Me.SqlConnection1

Me.SqlInsertCommand2.Parameters.Add(New System.Data.SqlClient.SqlParameter("@uspo", System.Data.SqlDbType.VarChar, 30, "uspo"))




Me.SqlSelectCommand2.CommandText = "SELECT uspo FROM dbo.officer ORDER BY uspo"

Me.SqlSelectCommand2.Connection = Me.SqlConnection1




Me.DataSet11.DataSetName = "DataSet1"

Me.DataSet11.Locale = New System.Globalization.CultureInfo("en-US")




Me.SqlDataAdapter3.InsertCommand = Me.SqlInsertCommand3

Me.SqlDataAdapter3.SelectCommand = Me.SqlSelectCommand3

Me.SqlDataAdapter3.TableMappings.AddRange(New System.Data.Common.DataTableMapping() {New System.Data.Common.DataTableMapping("Table", "casereview", New System.Data.Common.DataColumnMapping() {New System.Data.Common.DataColumnMapping("susponame", "susponame"), New System.Data.Common.DataColumnMapping("usponame", "usponame"), New System.Data.Common.DataColumnMapping("casename", "casename"), New System.Data.Common.DataColumnMapping("datesub", "datesub"), New System.Data.Common.DataColumnMapping("x1", "x1"), New System.Data.Common.DataColumnMapping("x2", "x2"), New System.Data.Common.DataColumnMapping("x3", "x3"), New System.Data.Common.DataColumnMapping("x4", "x4"), New System.Data.Common.DataColumnMapping("x5", "x5"), New System.Data.Common.DataColumnMapping("x6", "x6"), New System.Data.Common.DataColumnMapping("x7", "x7"), New System.Data.Common.DataColumnMapping("x8", "x8"), New System.Data.Common.DataColumnMapping("x9", "x9"), New System.Data.Common.DataColumnMapping("x10", "x10"), New System.Data.Common.DataColumnMapping("x11", "x11"), New System.Data.Common.DataColumnMapping("x12", "x12"), New System.Data.Common.DataColumnMapping("x13", "x13"), New System.Data.Common.DataColumnMapping("x14", "x14"), New System.Data.Common.DataColumnMapping("x15", "x15"), New System.Data.Common.DataColumnMapping("x16", "x16"), New System.Data.Common.DataColumnMapping("x17", "x17"), New System.Data.Common.DataColumnMapping("comment", "comment")})})




Me.SqlInsertCommand3.CommandText = "INSERT INTO dbo.casereview(susponame, usponame, casename, datesub, x1, x2, x3, x4" & _

", x5, x6, x7, x8, x9, x10, x11, x12, x13, x14, x15, x16, x17, comment) VALUES (@" & _

"susponame, @usponame, @casename, @datesub, @x1, @x2, @x3, @x4, @x5, @x6, @x7, @x" & _

"8, @x9, @x10, @x11, @x12, @x13, @x14, @x15, @x16, @x17, @comment); SELECT suspon" & _

"ame, usponame, casename, datesub, x1, x2, x3, x4, x5, x6, x7, x8, x9, x10, x11, " & _

"x12, x13, x14, x15, x16, x17, comment FROM dbo.casereview"

Me.SqlInsertCommand3.Connection = Me.SqlConnection1

Me.SqlInsertCommand3.Parameters.Add(New System.Data.SqlClient.SqlParameter("@susponame", System.Data.SqlDbType.VarChar, 30, "susponame"))

Me.SqlInsertCommand3.Parameters.Add(New System.Data.SqlClient.SqlParameter("@usponame", System.Data.SqlDbType.VarChar, 30, "usponame"))

Me.SqlInsertCommand3.Parameters.Add(New System.Data.SqlClient.SqlParameter("@casename", System.Data.SqlDbType.VarChar, 50, "casename"))

Me.SqlInsertCommand3.Parameters.Add(New System.Data.SqlClient.SqlParameter("@datesub", System.Data.SqlDbType.DateTime, 8, "datesub"))

Me.SqlInsertCommand3.Parameters.Add(New System.Data.SqlClient.SqlParameter("@x1", System.Data.SqlDbType.VarChar, 3, "x1"))

Me.SqlInsertCommand3.Parameters.Add(New System.Data.SqlClient.SqlParameter("@x2", System.Data.SqlDbType.VarChar, 3, "x2"))

Me.SqlInsertCommand3.Parameters.Add(New System.Data.SqlClient.SqlParameter("@x3", System.Data.SqlDbType.VarChar, 3, "x3"))

Me.SqlInsertCommand3.Parameters.Add(New System.Data.SqlClient.SqlParameter("@x4", System.Data.SqlDbType.VarChar, 3, "x4"))

Me.SqlInsertCommand3.Parameters.Add(New System.Data.SqlClient.SqlParameter("@x5", System.Data.SqlDbType.VarChar, 3, "x5"))

Me.SqlInsertCommand3.Parameters.Add(New System.Data.SqlClient.SqlParameter("@x6", System.Data.SqlDbType.VarChar, 3, "x6"))

Me.SqlInsertCommand3.Parameters.Add(New System.Data.SqlClient.SqlParameter("@x7", System.Data.SqlDbType.VarChar, 3, "x7"))

Me.SqlInsertCommand3.Parameters.Add(New System.Data.SqlClient.SqlParameter("@x8", System.Data.SqlDbType.VarChar, 3, "x8"))

Me.SqlInsertCommand3.Parameters.Add(New System.Data.SqlClient.SqlParameter("@x9", System.Data.SqlDbType.VarChar, 3, "x9"))

Me.SqlInsertCommand3.Parameters.Add(New System.Data.SqlClient.SqlParameter("@x10", System.Data.SqlDbType.VarChar, 3, "x10"))

Me.SqlInsertCommand3.Parameters.Add(New System.Data.SqlClient.SqlParameter("@x11", System.Data.SqlDbType.VarChar, 3, "x11"))

Me.SqlInsertCommand3.Parameters.Add(New System.Data.SqlClient.SqlParameter("@x12", System.Data.SqlDbType.VarChar, 3, "x12"))

Me.SqlInsertCommand3.Parameters.Add(New System.Data.SqlClient.SqlParameter("@x13", System.Data.SqlDbType.VarChar, 3, "x13"))

Me.SqlInsertCommand3.Parameters.Add(New System.Data.SqlClient.SqlParameter("@x14", System.Data.SqlDbType.VarChar, 3, "x14"))

Me.SqlInsertCommand3.Parameters.Add(New System.Data.SqlClient.SqlParameter("@x15", System.Data.SqlDbType.VarChar, 3, "x15"))

Me.SqlInsertCommand3.Parameters.Add(New System.Data.SqlClient.SqlParameter("@x16", System.Data.SqlDbType.VarChar, 3, "x16"))

Me.SqlInsertCommand3.Parameters.Add(New System.Data.SqlClient.SqlParameter("@x17", System.Data.SqlDbType.VarChar, 3, "x17"))

Me.SqlInsertCommand3.Parameters.Add(New System.Data.SqlClient.SqlParameter("@comment", System.Data.SqlDbType.VarChar, 2147483647, "comment"))




Me.SqlSelectCommand3.CommandText = "SELECT susponame, usponame, casename, datesub, x1, x2, x3, x4, x5, x6, x7, x8, x9" & _

", x10, x11, x12, x13, x14, x15, x16, x17, comment FROM dbo.casereview"

Me.SqlSelectCommand3.Connection = Me.SqlConnection1

CType(Me.DataSet11, System.ComponentModel.ISupportInitialize).EndInit()

End Sub

Protected WithEvents chkviolation As System.Web.UI.WebControls.CheckBox

Protected WithEvents chkfinal As System.Web.UI.WebControls.CheckBox

Protected WithEvents chkperiodic As System.Web.UI.WebControls.CheckBox

Protected WithEvents chkinitial As System.Web.UI.WebControls.CheckBox

Protected WithEvents btnreset As System.Web.UI.WebControls.Button

Protected WithEvents btnsubmit As System.Web.UI.WebControls.Button

Protected WithEvents SqlConnection1 As System.Data.SqlClient.SqlConnection

Protected WithEvents SqlDataAdapter1 As System.Data.SqlClient.SqlDataAdapter

Protected WithEvents SqlDataAdapter2 As System.Data.SqlClient.SqlDataAdapter

Protected WithEvents DataSet11 As norfolkcasereview.DataSet1

Protected WithEvents SqlDataAdapter3 As System.Data.SqlClient.SqlDataAdapter

Protected WithEvents SqlSelectCommand1 As System.Data.SqlClient.SqlCommand

Protected WithEvents SqlInsertCommand1 As System.Data.SqlClient.SqlCommand

Protected WithEvents SqlSelectCommand2 As System.Data.SqlClient.SqlCommand

Protected WithEvents SqlInsertCommand2 As System.Data.SqlClient.SqlCommand

Protected WithEvents txtcomments As System.Web.UI.WebControls.TextBox

Protected WithEvents lblcomments As System.Web.UI.WebControls.Label

Protected WithEvents rblx1 As System.Web.UI.WebControls.RadioButtonList

Protected WithEvents rblx7 As System.Web.UI.WebControls.RadioButtonList

Protected WithEvents rblx8 As System.Web.UI.WebControls.RadioButtonList

Protected WithEvents rblx9 As System.Web.UI.WebControls.RadioButtonList

Protected WithEvents rblx10 As System.Web.UI.WebControls.RadioButtonList

Protected WithEvents rblx11 As System.Web.UI.WebControls.RadioButtonList

Protected WithEvents rblx12 As System.Web.UI.WebControls.RadioButtonList

Protected WithEvents rblx13 As System.Web.UI.WebControls.RadioButtonList

Protected WithEvents lblcasename As System.Web.UI.WebControls.Label

Protected WithEvents lbluspo As System.Web.UI.WebControls.Label

Protected WithEvents lbldatesub As System.Web.UI.WebControls.Label

Protected WithEvents ddlsuspo As System.Web.UI.WebControls.DropDownList

Protected WithEvents ddluspo As System.Web.UI.WebControls.DropDownList

Protected WithEvents txtcase As System.Web.UI.WebControls.TextBox

Protected WithEvents txtdate As System.Web.UI.WebControls.TextBox

Protected WithEvents SqlSelectCommand3 As System.Data.SqlClient.SqlCommand

Protected WithEvents SqlInsertCommand3 As System.Data.SqlClient.SqlCommand

Protected WithEvents RequiredFieldValidator1 As System.Web.UI.WebControls.RequiredFieldValidator

Protected WithEvents RequiredFieldValidator2 As System.Web.UI.WebControls.RequiredFieldValidator

Protected WithEvents lblsuspo As System.Web.UI.WebControls.Label

'NOTE: The following placeholder declaration is required by the Web Form Designer.

'Do not delete or move it.

Private designerPlaceholderDeclaration As System.Object

Private Sub Page_Init(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Init

'CODEGEN: This method call is required by the Web Form Designer

'Do not modify it using the code editor.


End Sub

#End Region

Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load





End Sub

Private Sub btnsubmit_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnsubmit.Click

Dim rw As DataSet1.casereviewRow

rw = Me.DataSet11.casereview.NewcasereviewRow

rw.susponame = Me.ddlsuspo.SelectedValue

rw.usponame = Me.ddluspo.SelectedValue

rw.casename = Me.txtcase.Text

rw.datesub = Me.txtdate.Text

rw.final = Me.chkfinal.Checked

rw.x1 = Me.rblx1.SelectedValue

rw.x7 = Me.rblx7.SelectedValue

rw.x8 = Me.rblx8.SelectedValue

rw.x9 = Me.rblx9.SelectedValue

rw.x10 = Me.rblx10.SelectedValue

rw.x11 = Me.rblx11.SelectedValue

rw.x12 = Me.rblx12.SelectedValue

rw.x13 = Me.rblx13.SelectedValue

rw.comment = Me.txtcomments.Text







End Sub

10/13/2005 4:29:47 PM
asp.net.web-forms 93655 articles. 6 followers. Follow

1 Replies

Similar Articles

[PageSpeed] 16

Change your code to this (see red lines)

Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
    If Not IsPostBack Then
    End If
End Sub

10/13/2005 6:41:12 PM

Similar Artilces:

Dropdownlist selected value passes first value in list no matter what value is selected. why ?
 HI . I have a dropdownlist. Databinds ok but when I must pass a value as a Selected value it always passes the first value in the list even if I select another value. I tried to set the ddl to enableviewstate false but it doesn't change anything. Any ideas ? Code below, thanksLoading the ddl:       productCategories = CatalogAdmin.Admin_Product_Categories_NotIn(productId);        for (int i = 0; i < productCategories.Rows.Count; i++)        {       &...

Drop down list in Form view returns error when value in bound field (data binding
I get the following error when I click edit to edit the details in the web form:'ddlUserRestrictionType' has a SelectedValue which is invalid because it does not exist in the list of items.Parameter name: value  I would like it to accept any value which currently exists in the database. Is this easily achievable? With what you've posted, all I can tell is that you are trying to set the SelectedValue of a ddl to a value that does not exist in the list.  It would be helpful if you can post some code and the expected values of this control.~ Timwww.bucketo...

Cascading Dropdown List
Hi, First post so hello and need some help with an issue I have been dealing with.  I have an intranet page I created in ASP.NET using C# .NET 3.5 with a few Ajax Extenders including 3 Cascading Dropdown Lists. Now I have used the Cascading dropdown lists for my own purposes i.e they do not actually cascade their results to another dropdown list, the reason I did this was due to the having a User Control that contains an update panel and other bits i.e I didn't want the control/page posting page (something that happens when you click on a regular dropdown list). Everything is wor...

adding values to the selected value in Dropdown list
 Hi,   I have dropdown box in my page which have some value inherted from the another list box in my page..Now in my second page , i have dropdown box with values and text value and list box... I'll be selecting the one value from the dropdown then i enter the value in text box and click on add button which will add the value in the list box like this i can able to add many value...now if i click on save button for the selected dropdpown item the added values in the listbox should be saved ...like this i add many values for many dropdown item and saved respectivelynow if c...

How to show value in textbox from selected value in Dropdown list
I have two text box, txtbox1 should be from two field for example i have one dropdownlist where i select item and another txtbox2 i want to put value, when i first time to write manually value in txtbox2 in and selected item from ddl i want to result in concatenate from in txtbox1. for example  I haveif not me.ispostback thenDim cm as new sqlcommand("Select AccMjrid, Names from Accgrp", me.sqlconnection1.open())me.sqldataAdapter1.fill(Dataset1, "Accgrp") Me.cmbAccMajID.DataSource = Me.DataSet11.Tables("AccMajor") Me.cmbAccMajID.DataTextField = "AccName" Me.cmbAccMajID.DataValueField ...

Dropdown list only selects first value
I have a dropdownlist that is populated with from a common list. The control is populated correctly but when I submit the value is reset to the first Item in the list.For example:I have a dropdown with the following values value1 value2 value3No matter which item I select the value saved to the database is value1.What am I doing wrong? Fixed this one myself.  Left databind outside postback conditional statement.  Couldn't see the forest for the trees. Hmmm. We're having a similar problem. We have a modified ContactUs module that allows the user to select a subject from a...

dropdown selected value and dropdown no value saved
 is there any way the selected value is selected already when i try to edit the gridview ... and another thing... when i edit this dropdown.. no value was being saved... what is wrong or missing.. please help... i almost spend two days on this problem...i've read many post about this.. but still i didn;t get it... please help///  <asp:TemplateField HeaderText="Unit" SortExpression="UnitID">                          &...

can i drag the selected value of dropdown list in one web part to another web part
hi, supose i am having time displaying in on webpart can i drag the value of time to another web part and and display the time is: and the value draged from the other webpart so i want to drag the value year and population into antoher web part and according to that the grap must appear i.e what  i exactly want is i must drag some value from one webpart to onother webpart and according to event some thing must happen in another web part   Hi, The problem has been replied in the following post: http://forums.asp.net/t/1141884.aspx But from the title you described, do ...

How to get value from first dropdown list to second dropdown list
Hi Does soneone know hot to get value from first dropdown list to second dropdown list or remove it from seond dropdown list? I have a web form page. On the page, there are two dropdown lists, one Add button, and one Remove button . First dropdown list has four list items. Second one does not have list item yet. When select a item from first dropdown list, then click "add" button. I want it to apear in the second dropdown list without reload the page. Or select item from second dropdown list, and click "Remove" button. it will remove from second list. Please help. &nb...

first selected value disappears from dropdown list
With the following code, the initial index of 0 disappears from ddlGroups when the selected value changes. Any suggestions?     Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load        Dim strSQL As String = "W_SP_SELECT_GROUPS"        ddlGroups.Visible = True        lblUsers.Visible = False        ddlUsers.Visible = False        ddlUsers.Sele...

Selected value of a dropdown list, submit to database.
Hi. I have a dropdownlist that I populate from a database (works).  When a user selects a value in the list and submits, the page gets reloaded with the values that are left in the dropdownlis (minus the one that was just submitted).  The submission works fine if the user goes down the list top to bottom, one by one until everything is gone.  However, if the user say selects the third item in the list and submits, it still submits the top item instead. Which of course causes issues. I am setting the value of the item to submit as ddl.selectedvalue... whats the issue? Sourc...

Password text value gets deleted when value selected from Dropdown list
Hi, I need help in my dropdown control, this is what my problem is I am using DropDown List in my aplication in a form and i want to show some default selected value in the first drop down D1 and depending on values selected in D1 the values gets displayed in the child drop down D2. My issue is i have a password texbox before getting valued from D1 and D2......when i select value from D1 the password enetered in hte password textbox in password mode gets deleted. so every time he user types the password and then select something in the dropdown, he has to ...

Populate dropdown list based on selected value in another dropdown list
I have a datagrid (grdCar) that contains two dropdown listboxes (ddlCarManf and ddlCar). When the user clicks the "Edit" link and places the grid into edit mode, they select a value in ddlCarManf. Based on the selected value in ddlCarManf, I need to then populate ddlCar with a list of cars for which the selected manufacturer makes (I'm using ddlCarManf.SelectedValue to query the database).  I bind my datagrid in the page_load event as: If Not Page.IsPostBack Then    BindGrid() End If Here is my control (ddlCarManf) as is appears within grdCar in ...

Displaying values from 3 textboxes automatically after selecting a value from a dropdown list
 The dropdown list is databind to a sqldatasource from the Bike Table.After selecting a bike Name from the dropdown list, the status and rent price will be displayed on the 2 textboxes automatically.Both the status and  rent price values are taken from the same Bike Table.Can anyone help me with this?Thanks. On the selected index change property of the dropdownlist hit the database to get the details (status and rent ) for the selected Item and set the values to the text of textboxes.Hope this helps. Just do this in your OnSelectedIndexChanged event of the ddlSqlCommand cmd =...