By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
444,219 Members | 2,147 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 444,219 IT Pros & Developers. It's quick & easy.

Why is this keeping the old values?

P: n/a
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.Conn ectionString",
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

Nov 21 '05 #1
Share this Question
Share on Google+
3 Replies


P: n/a
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.

"robboll" <ro*****@hotmail.com> wrote in message
news:11**********************@o13g2000cwo.googlegr oups.com...
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.Conn ectionString",
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

Nov 21 '05 #2

P: n/a
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

Nov 21 '05 #3

P: n/a
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.

"robboll" <ro*****@hotmail.com> wrote in message
news:11*********************@f14g2000cwb.googlegro ups.com...
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

Nov 21 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.