Hi, forum newbie here, and I'm almost in tears having finally cracked one bit of code this morning after a mere two weeks, only to get stuck on the next bit.
I have managed to put together code so that when my FormView is in edit mode and I click save, an update can be made to the database if the new value is hard coded in. What I am failing on is how to obtain the value that I have just typed into the FormView before pressing save. I have started with just one field:
This is my ItemUpdating handler:
I've read through no end of other forums today, but either (a) what I have found isn't the right answer or morelikely (b) I just can't put this into practice since I'm not the worlds greatest programmer.
Any help offered would be greatly appreciated, even if it's likely just to progress me to the next problem.
I have managed to put together code so that when my FormView is in edit mode and I click save, an update can be made to the database if the new value is hard coded in. What I am failing on is how to obtain the value that I have just typed into the FormView before pressing save. I have started with just one field:
VB.NET:
<asp:TextBox ID="BaseLocationPostalCodeTextBox" runat="server" Text='<%# Bind("BaseLocationPostalCode") %>'
style="position: absolute; left: 684px; top: 215px" ReadOnly="false" ></asp:TextBox>
This is my ItemUpdating handler:
VB.NET:
Public Sub AandAFormView_ItemUpdating(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.FormViewUpdateEventArgs)
Handles AandAFormView.ItemUpdating
'From http://msdn.microsoft.com/en-us/library/33y2221y(VS.71).aspx
Dim AandASelectQueryString As String = "" & _
"SELECT ConsultantApplications.ConsultantApplicationID, Titles.ListObject AS Title, ... " & _
"FROM ListObjects AS Titles RIGHT OUTER JOIN ... " & _
"WHERE ConsultantApplications.ConsultantApplicationID = " & (gv.ConsultantApplicationID) & " " & _
"GROUP BY ConsultantApplications.ConsultantApplicationID, Contacts.ContactFirstName... " & _
"ORDER BY ConsultantApplications.ConsultantApplicationID" 'AandA select query string
AandADataAdapter = New SqlDataAdapter(AandASelectQueryString, gv.Connection)
Dim AandAUpdateQueryString As String = "" & _
"UPDATE ConsultantApplications " & _
"SET ConsultantApplications.BaseLocationPostalCode = @BaseLocationPostalCode " & _
"WHERE ConsultantApplications.ConsultantApplicationID = @ConsultantApplicationID" 'AandA update query string
AandADataAdapter.UpdateCommand = New SqlCommand(AandAUpdateQueryString, gv.Connection)
AandADataAdapter.UpdateCommand.Parameters.Add("@BaseLocationPostalCode", SqlDbType.NVarChar, 15, "BaseLocationPostalCode")
Dim workParm As SqlParameter = AandADataAdapter.UpdateCommand.Parameters.Add("@ConsultantApplicationID", SqlDbType.Int)
workParm.SourceColumn = "ConsultantApplicationID"
workParm.SourceVersion = DataRowVersion.Original
gv.ConsultantDataSet = New DataSet
AandADataAdapter.Fill(gv.ConsultantDataSet, "AandA")
Dim AandADataRow As DataRow = gv.ConsultantDataSet.Tables("AandA").Rows(0)
AandADataRow("BaseLocationPostalCode") = "SW16 2LJ" 'This code works fine if I hard code an updated value in here
AandADataAdapter.Update(gv.ConsultantDataSet, "AandA")
AandAFormView.ChangeMode(FormViewMode.ReadOnly)
AandAFormView.DataSource = GetAandAData()
AandAFormView.DataBind()
End Sub
I've read through no end of other forums today, but either (a) what I have found isn't the right answer or morelikely (b) I just can't put this into practice since I'm not the worlds greatest programmer.
Any help offered would be greatly appreciated, even if it's likely just to progress me to the next problem.