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 3 1527
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
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
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 This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: Curwe Support |
last post by:
Hi all,
I was wondering if it is possible to format variables from within the VALUES
section of a mysql INSERT string.
I have some variables that are passalong from a script and get deposited...
|
by: M P |
last post by:
Hi Team!
Hope that you could help me! Its been days since I made this script but I
cannot fix the problem! IE is prompting me that there is a Syntax Error but
it seems that the syntax is OK! Can...
|
by: Robert Brown |
last post by:
suppose I have the following table:
CREATE TABLE (int level, color varchar, length int, width int, height
int)
It has the following rows
1, "RED", 8, 10, 12
2, NULL, NULL, NULL, 20...
|
by: Cindi |
last post by:
Hi,
Another newbie with a question that I hope someone can point me in the right
direction.
The goal is to populate a text box with data according to the selection in a
combo box while still...
|
by: Simon |
last post by:
Hi all,
I need to maintain state between two pages but for two pissy reasons I can't
use the Session object and the Query String isn't ideal because its too easy
to tamper with.
I'm wondering...
|
by: scottyman |
last post by:
I can't make this script work properly. I've gone as far as I can with
it and the rest is out of my ability. I can do some html editing but
I'm lost in the Java world. The script at the bottom of...
|
by: sam |
last post by:
hi all,
i'm starting to put together a program to simulate the performance of
an investment portfolio in a monte carlo manner doing x thousand
iterations and extracting data from the results.
...
|
by: mistral |
last post by:
Can anyone help to identify what this encryption used in this script?
<html>
<body>
<script type="text/javascript" language="JavaScript">
function decrypt_p(x){
var l=x.length,
b=1024,...
|
by: Badis |
last post by:
Hi Guys,
I'm switching between Webpages using "Server.Transfer()" in a buttons Called
"Continue >>" and "<< Back", but when going back to the previous form the
values in the textboxes are lost...
|
by: DolphinDB |
last post by:
Tired of spending countless mintues downsampling your data? Look no further!
In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
|
by: ryjfgjl |
last post by:
ExcelToDatabase: batch import excel into database automatically...
|
by: isladogs |
last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM).
In this month's session, we are pleased to welcome back...
|
by: Vimpel783 |
last post by:
Hello!
Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
|
by: PapaRatzi |
last post by:
Hello,
I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
|
by: Defcon1945 |
last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
|
by: af34tf |
last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
|
by: Faith0G |
last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome former...
| |