Why is this keeping the old values?


R

robboll

I am building an ASP.NET data entry form and when I change the values
per the dropdowns and click "save", the old values remain. Are there
any suggestions on how to update the variables to the latest data
selections?

***** The code: *******************************************

Imports System.Data.SqlClient

Public Class WebForm1
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()
Dim configurationAppSettings As
System.Configuration.AppSettingsReader = New
System.Configuration.AppSettingsReader
Me.conn = New System.Data.SqlClient.SqlConnection
'
'conn
'
Me.conn.ConnectionString =
CType(configurationAppSettings.GetValue("conn.ConnectionString",
GetType(System.String)), String)

End Sub
Protected WithEvents TextBox1 As System.Web.UI.WebControls.TextBox
Protected WithEvents conn As System.Data.SqlClient.SqlConnection
Protected WithEvents ddlRequestor As
System.Web.UI.WebControls.DropDownList
Protected WithEvents Label1 As System.Web.UI.WebControls.Label
Protected WithEvents ddlDivMgr As
System.Web.UI.WebControls.DropDownList
Protected WithEvents Label2 As System.Web.UI.WebControls.Label
Protected WithEvents Label3 As System.Web.UI.WebControls.Label
Protected WithEvents Label4 As System.Web.UI.WebControls.Label
Protected WithEvents Label5 As System.Web.UI.WebControls.Label
Protected WithEvents tbxDescription As
System.Web.UI.WebControls.TextBox
Protected WithEvents tbxChangeName As
System.Web.UI.WebControls.TextBox
Protected WithEvents Label6 As System.Web.UI.WebControls.Label
Protected WithEvents ddlChangeType As
System.Web.UI.WebControls.DropDownList
Protected WithEvents Button1 As System.Web.UI.WebControls.Button

'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.
InitializeComponent()
End Sub

#End Region
Dim ds As New DataSet

Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
'Put user code to initialize the page here
Dim query As String
'Dim ds As New DataSet
query = "select names from requestor order by names"
Dim da As New SqlDataAdapter(query, conn)
da.Fill(ds, "Requestor")
ddlRequestor.DataSource = ds
ddlRequestor.DataMember = "Requestor"
ddlRequestor.DataTextField = "names"
ddlRequestor.DataBind()

query = "select DivMgr from DivMgr order by DivMgr"
Dim daDivMgr As New SqlDataAdapter(query, conn)
daDivMgr.Fill(ds, "DivMgr")
ddlDivMgr.DataSource = ds
ddlDivMgr.DataMember = "DivMgr"
ddlDivMgr.DataTextField = "DivMgr"
ddlDivMgr.DataBind()

query = "select Type from ChgType order by Type"
Dim daChangeType As New SqlDataAdapter(query, conn)
daChangeType.Fill(ds, "ChgType")
ddlChangeType.DataSource = ds
ddlChangeType.DataMember = "ChgType"
ddlChangeType.DataTextField = "Type"
ddlChangeType.DataBind()

End Sub

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button1.Click
Dim daRequests As New SqlDataAdapter
Dim Query, mDivMan, mChgType, mRequestor As String

mDivMan = ddlDivMgr.SelectedValue
mChgType = ddlChangeType.SelectedValue
mRequestor = ddlRequestor.SelectedValue

Query = "Insert into Requests (Divman, ChangeType, Requestor)"
& _
"values('" & mDivMan & "', '" & mChgType & "', '" & mRequestor
& "')"

Dim objcommand As New SqlClient.SqlCommand(query, conn)

objcommand.Connection.Open()
objcommand.ExecuteNonQuery()
objcommand.Connection.Close()
objcommand.Dispose()
objcommand = Nothing



End Sub
End Class
 
Ad

Advertisements

M

Marina

You are replacing the value in Page_Load. So no matter what the user
selects, the data gets rebound and reselected - that is what you are seeing.
 
R

robboll

Thanks Marina. Someone actually get me started with the coding. I
don't think they realized that it shouldn't be in Page_Load. But If
not Page_Load -- how do I code it so that the value selected in the
dropdown is what is written to the database? I think I'll be able to
complete the project after I get beyond that hurdle.

RBollinger
 
Ad

Advertisements

M

Marina

You should keep it in page_load, but put it inside an 'If Not IsPostback
Then' statement, so that it only happens on the initial load of the page.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top