Do you have autoeventwireup=true on the top of your ASPX page? Otherwise page_load won't fire.
Aha it was set to false ... and now this:
Server Error in '/HRIService' Application.
Object reference not set to an instance of an object.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
Exception Details: System.NullReferenceException: Object reference not set to an instance of an object.
Source Error:
Line 84:
Line 85: If Not cusID Is Nothing And Not conID Is Nothing And Len(cusID) > 1 And Len(conID) > 1 Then
Line 86: DropDownList1.Items.FindByValue(cusID).Selected = True
Line 87: DropDownList1_SelectedIndexChanged(DropDownList1, e)
Line 88:
Source File: C:\Inetpub\wwwroot\HRIService\ServiceExpress\AddCall.aspx.vb Line: 86
Gosh I hate code-behind. lol. Didn't specify the control or find it
Partial Class AddCall
Inherits System.Web.UI.Page
Protected Sub DropDownList1_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles DropDownList1.SelectedIndexChanged
Dim FirstName As TextBox = TryCast(FormView1.FindControl("FirstName"), TextBox)
Dim LastName As TextBox = TryCast(FormView1.FindControl("LastName"), TextBox)
DropDownList2.SelectedIndex = 0
FirstName.Text = ""
LastName.Text = ""
End Sub
Protected Sub DropDownList2_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles DropDownList2.SelectedIndexChanged
'labelSelection.Text = DropDownList1.SelectedItem.Text & " " & DropDownList2.SelectedItem.Text
Dim Company As TextBox = TryCast(FormView1.FindControl("Company"), TextBox)
Dim Address1 As TextBox = TryCast(FormView1.FindControl("Address1"), TextBox)
Dim Address2 As TextBox = TryCast(FormView1.FindControl("Address2"), TextBox)
Dim Phone As TextBox = TryCast(FormView1.FindControl("Phone"), TextBox)
Dim FirstName As TextBox = TryCast(FormView1.FindControl("FirstName"), TextBox)
Dim LastName As TextBox = TryCast(FormView1.FindControl("LastName"), TextBox)
Dim City As TextBox = TryCast(FormView1.FindControl("City"), TextBox)
Dim State As TextBox = TryCast(FormView1.FindControl("State"), TextBox)
Dim Zip As TextBox = TryCast(FormView1.FindControl("Zip"), TextBox)
Dim str_sql As String = "SELECT * FROM Customers WHERE cusID = " & DropDownList1.SelectedValue
Using connection As New System.Data.SqlClient.SqlConnection("Data Source=IT-P02\SQLEXPRESS;Initial Catalog=HRIService;Integrated Security=True")
Dim command As New System.Data.SqlClient.SqlCommand(str_sql, connection)
Try
connection.Open()
Dim reader As System.Data.SqlClient.SqlDataReader = command.ExecuteReader()
If reader.HasRows then
while reader.Read()
Company.Text = reader.Item("Company").ToString
Address1.Text = reader.Item("Address1").ToString
Address2.Text = reader.Item("Address2").ToString
Phone.Text = reader.Item("Phone").ToString
end while
End If
reader.Close()
str_sql = "SELECT * FROM CONTACTS WHERE cusID = " & DropDownList2.SelectedValue
command = New System.Data.SqlClient.SqlCommand(str_sql, connection)
reader = command.ExecuteReader()
If reader.HasRows then
while reader.Read()
FirstName.Text = reader.Item("FirstName").ToString()
LastName.Text = reader.Item("LastName").ToString()
end while
End If
reader.Close()
str_sql = "SELECT * FROM Zip WHERE cusID = " & DropDownList1.SelectedValue
command = New System.Data.SqlClient.SqlCommand(str_sql, connection)
reader = command.ExecuteReader()
If reader.HasRows then
while reader.Read()
City.Text = reader.Item("City").ToString()
State.Text = reader.Item("State").ToString()
Zip.Text = reader.Item("Zip").ToString()
end while
End If
reader.Close()
connection.Close()
Catch ex As System.Data.SqlClient.SqlException
End Try
End Using
End Sub
Protected Sub Page_Load(ByVal S As Object, ByVal E As System.EventArgs)
Dim cusID As String = Trim(Request.QueryString("cusID"))
Dim conID As String = Trim(Request.QueryString("conID"))
if Not cusID Is Nothing and Not conID Is Nothing and Len(cusID) > 1 and Len(conID) > 1 then
response.write("11111111111111111111111111")
Dim DropDownList1 As DropDownList = TryCast(FormView1.FindControl("DropDownList1"), DropDownList)
Dim DropDownList2 As DropDownList = TryCast(FormView1.FindControl("DropDownList2"), DropDownList)
DropDownList1.Items.FindByValue(cusID).Selected = True
DropDownList1_SelectedIndexChanged(DropDownList1, e)
DropDownList2.Items.FindByValue(conID).Selected = True
DropDownList2_SelectedIndexChanged(DropDownList2, e)
else
response.write("22222222222222222222222222")
end if
End Sub
Protected Sub DropDownListEquip_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs)
End Sub
End Class
Voila ...
Server Error in '/HRIService' Application.
Object reference not set to an instance of an object.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
Exception Details: System.NullReferenceException: Object reference not set to an instance of an object.
Source Error:
Line 87: Dim DropDownList1 As DropDownList = TryCast(FormView1.FindControl("DropDownList1"), DropDownList)
Line 88: Dim DropDownList2 As DropDownList = TryCast(FormView1.FindControl("DropDownList2"), DropDownList)
Line 89: DropDownList1.Items.FindByValue(cusID).Selected = True
Line 90: DropDownList1_SelectedIndexChanged(DropDownList1, e)
Line 91:
Source File: C:\Inetpub\wwwroot\HRIService\ServiceExpress\AddCall.aspx.vb Line: 89
Ok I give up on code-behind. Just use this code:
Partial Class AddCall
Inherits System.Web.UI.Page
Protected Sub DropDownList1_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles DropDownList1.SelectedIndexChanged
Dim FirstName As TextBox = TryCast(FormView1.FindControl("FirstName"), TextBox)
Dim LastName As TextBox = TryCast(FormView1.FindControl("LastName"), TextBox)
Dim DropDownList2 As DropDownList = TryCast(FormView1.FindControl("DropDownList2"), DropDownList)
DropDownList2.SelectedIndex = 0
FirstName.Text = ""
LastName.Text = ""
End Sub
Protected Sub DropDownList2_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles DropDownList2.SelectedIndexChanged
'labelSelection.Text = DropDownList1.SelectedItem.Text & " " & DropDownList2.SelectedItem.Text
Dim Company As TextBox = TryCast(FormView1.FindControl("Company"), TextBox)
Dim Address1 As TextBox = TryCast(FormView1.FindControl("Address1"), TextBox)
Dim Address2 As TextBox = TryCast(FormView1.FindControl("Address2"), TextBox)
Dim Phone As TextBox = TryCast(FormView1.FindControl("Phone"), TextBox)
Dim FirstName As TextBox = TryCast(FormView1.FindControl("FirstName"), TextBox)
Dim LastName As TextBox = TryCast(FormView1.FindControl("LastName"), TextBox)
Dim City As TextBox = TryCast(FormView1.FindControl("City"), TextBox)
Dim State As TextBox = TryCast(FormView1.FindControl("State"), TextBox)
Dim Zip As TextBox = TryCast(FormView1.FindControl("Zip"), TextBox)
Dim str_sql As String = "SELECT * FROM Customers WHERE cusID = " & DropDownList1.SelectedValue
Using connection As New System.Data.SqlClient.SqlConnection("Data Source=IT-P02\SQLEXPRESS;Initial Catalog=HRIService;Integrated Security=True")
Dim command As New System.Data.SqlClient.SqlCommand(str_sql, connection)
Try
connection.Open()
Dim reader As System.Data.SqlClient.SqlDataReader = command.ExecuteReader()
If reader.HasRows then
while reader.Read()
Company.Text = reader.Item("Company").ToString
Address1.Text = reader.Item("Address1").ToString
Address2.Text = reader.Item("Address2").ToString
Phone.Text = reader.Item("Phone").ToString
end while
End If
reader.Close()
str_sql = "SELECT * FROM CONTACTS WHERE cusID = " & DropDownList2.SelectedValue
command = New System.Data.SqlClient.SqlCommand(str_sql, connection)
reader = command.ExecuteReader()
If reader.HasRows then
while reader.Read()
FirstName.Text = reader.Item("FirstName").ToString()
LastName.Text = reader.Item("LastName").ToString()
end while
End If
reader.Close()
str_sql = "SELECT * FROM Zip WHERE cusID = " & DropDownList1.SelectedValue
command = New System.Data.SqlClient.SqlCommand(str_sql, connection)
reader = command.ExecuteReader()
If reader.HasRows then
while reader.Read()
City.Text = reader.Item("City").ToString()
State.Text = reader.Item("State").ToString()
Zip.Text = reader.Item("Zip").ToString()
end while
End If
reader.Close()
connection.Close()
Catch
End Try
End Using
End Sub
Protected Sub Page_Load(ByVal S As Object, ByVal E As System.EventArgs)
Dim cusID As String = Trim(Request.QueryString("cusID"))
Dim conID As String = Trim(Request.QueryString("conID"))
if Not cusID Is Nothing and Not conID Is Nothing and Len(cusID) > 1 and Len(conID) > 1 then
'labelSelection.Text = DropDownList1.SelectedItem.Text & " " & DropDownList2.SelectedItem.Text
Dim Company As TextBox = TryCast(FormView1.FindControl("Company"), TextBox)
Dim Address1 As TextBox = TryCast(FormView1.FindControl("Address1"), TextBox)
Dim Address2 As TextBox = TryCast(FormView1.FindControl("Address2"), TextBox)
Dim Phone As TextBox = TryCast(FormView1.FindControl("Phone"), TextBox)
Dim FirstName As TextBox = TryCast(FormView1.FindControl("FirstName"), TextBox)
Dim LastName As TextBox = TryCast(FormView1.FindControl("LastName"), TextBox)
Dim City As TextBox = TryCast(FormView1.FindControl("City"), TextBox)
Dim State As TextBox = TryCast(FormView1.FindControl("State"), TextBox)
Dim Zip As TextBox = TryCast(FormView1.FindControl("Zip"), TextBox)
Dim str_sql As String = "SELECT * FROM Customers WHERE cusID = " & DropDownList1.SelectedValue
Using connection As New System.Data.SqlClient.SqlConnection("Data Source=IT-P02\SQLEXPRESS;Initial Catalog=HRIService;Integrated Security=True")
Dim command As New System.Data.SqlClient.SqlCommand(str_sql, connection)
Try
connection.Open()
Dim reader As System.Data.SqlClient.SqlDataReader = command.ExecuteReader()
If reader.HasRows then
while reader.Read()
Company.Text = reader.Item("Company").ToString
Address1.Text = reader.Item("Address1").ToString
Address2.Text = reader.Item("Address2").ToString
Phone.Text = reader.Item("Phone").ToString
end while
End If
reader.Close()
str_sql = "SELECT * FROM CONTACTS WHERE cusID = " & DropDownList2.SelectedValue
command = New System.Data.SqlClient.SqlCommand(str_sql, connection)
reader = command.ExecuteReader()
If reader.HasRows then
while reader.Read()
FirstName.Text = reader.Item("FirstName").ToString()
LastName.Text = reader.Item("LastName").ToString()
end while
End If
reader.Close()
str_sql = "SELECT * FROM Zip WHERE cusID = " & DropDownList1.SelectedValue
command = New System.Data.SqlClient.SqlCommand(str_sql, connection)
reader = command.ExecuteReader()
If reader.HasRows then
while reader.Read()
City.Text = reader.Item("City").ToString()
State.Text = reader.Item("State").ToString()
Zip.Text = reader.Item("Zip").ToString()
end while
End If
reader.Close()
connection.Close()
Catch
End Try
End Using
end if
End Sub
Protected Sub DropDownListEquip_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs)
End Sub
End Class
No errors and nothing in the text fields or ddls.
ok try this, and let me know what number displays:
Partial Class AddCall
Inherits System.Web.UI.Page
Protected Sub DropDownList1_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles DropDownList1.SelectedIndexChanged
Dim FirstName As TextBox = TryCast(FormView1.FindControl("FirstName"), TextBox)
Dim LastName As TextBox = TryCast(FormView1.FindControl("LastName"), TextBox)
Dim DropDownList2 As DropDownList = TryCast(FormView1.FindControl("DropDownList2"), DropDownList)
DropDownList2.SelectedIndex = 0
FirstName.Text = ""
LastName.Text = ""
End Sub
Protected Sub DropDownList2_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles DropDownList2.SelectedIndexChanged
'labelSelection.Text = DropDownList1.SelectedItem.Text & " " & DropDownList2.SelectedItem.Text
Dim Company As TextBox = TryCast(FormView1.FindControl("Company"), TextBox)
Dim Address1 As TextBox = TryCast(FormView1.FindControl("Address1"), TextBox)
Dim Address2 As TextBox = TryCast(FormView1.FindControl("Address2"), TextBox)
Dim Phone As TextBox = TryCast(FormView1.FindControl("Phone"), TextBox)
Dim FirstName As TextBox = TryCast(FormView1.FindControl("FirstName"), TextBox)
Dim LastName As TextBox = TryCast(FormView1.FindControl("LastName"), TextBox)
Dim City As TextBox = TryCast(FormView1.FindControl("City"), TextBox)
Dim State As TextBox = TryCast(FormView1.FindControl("State"), TextBox)
Dim Zip As TextBox = TryCast(FormView1.FindControl("Zip"), TextBox)
Dim str_sql As String = "SELECT * FROM Customers WHERE cusID = " & DropDownList1.SelectedValue
Using connection As New System.Data.SqlClient.SqlConnection("Data Source=IT-P02\SQLEXPRESS;Initial Catalog=HRIService;Integrated Security=True")
Dim command As New System.Data.SqlClient.SqlCommand(str_sql, connection)
Try
connection.Open()
Dim reader As System.Data.SqlClient.SqlDataReader = command.ExecuteReader()
If reader.HasRows then
while reader.Read()
Company.Text = reader.Item("Company").ToString
Address1.Text = reader.Item("Address1").ToString
Address2.Text = reader.Item("Address2").ToString
Phone.Text = reader.Item("Phone").ToString
end while
End If
reader.Close()
str_sql = "SELECT * FROM CONTACTS WHERE cusID = " & DropDownList2.SelectedValue
command = New System.Data.SqlClient.SqlCommand(str_sql, connection)
reader = command.ExecuteReader()
If reader.HasRows then
while reader.Read()
FirstName.Text = reader.Item("FirstName").ToString()
LastName.Text = reader.Item("LastName").ToString()
end while
End If
reader.Close()
str_sql = "SELECT * FROM Zip WHERE cusID = " & DropDownList1.SelectedValue
command = New System.Data.SqlClient.SqlCommand(str_sql, connection)
reader = command.ExecuteReader()
If reader.HasRows then
while reader.Read()
City.Text = reader.Item("City").ToString()
State.Text = reader.Item("State").ToString()
Zip.Text = reader.Item("Zip").ToString()
end while
End If
reader.Close()
connection.Close()
Catch
End Try
End Using
End Sub
Protected Sub Page_Load(ByVal S As Object, ByVal E As System.EventArgs)
Dim cusID As String = Trim(Request.QueryString("cusID"))
Dim conID As String = Trim(Request.QueryString("conID"))
if Not cusID Is Nothing and Not conID Is Nothing and Len(cusID) > 1 and Len(conID) > 1 then
response.write("1111111111111111111111111")
'labelSelection.Text = DropDownList1.SelectedItem.Text & " " & DropDownList2.SelectedItem.Text
Dim Company As TextBox = TryCast(FormView1.FindControl("Company"), TextBox)
Dim Address1 As TextBox = TryCast(FormView1.FindControl("Address1"), TextBox)
Dim Address2 As TextBox = TryCast(FormView1.FindControl("Address2"), TextBox)
Dim Phone As TextBox = TryCast(FormView1.FindControl("Phone"), TextBox)
Dim FirstName As TextBox = TryCast(FormView1.FindControl("FirstName"), TextBox)
Dim LastName As TextBox = TryCast(FormView1.FindControl("LastName"), TextBox)
Dim City As TextBox = TryCast(FormView1.FindControl("City"), TextBox)
Dim State As TextBox = TryCast(FormView1.FindControl("State"), TextBox)
Dim Zip As TextBox = TryCast(FormView1.FindControl("Zip"), TextBox)
Dim str_sql As String = "SELECT * FROM Customers WHERE cusID = " & DropDownList1.SelectedValue
Using connection As New System.Data.SqlClient.SqlConnection("Data Source=IT-P02\SQLEXPRESS;Initial Catalog=HRIService;Integrated Security=True")
Dim command As New System.Data.SqlClient.SqlCommand(str_sql, connection)
Try
connection.Open()
Dim reader As System.Data.SqlClient.SqlDataReader = command.ExecuteReader()
If reader.HasRows then
while reader.Read()
Company.Text = reader.Item("Company").ToString
Address1.Text = reader.Item("Address1").ToString
Address2.Text = reader.Item("Address2").ToString
Phone.Text = reader.Item("Phone").ToString
end while
End If
reader.Close()
str_sql = "SELECT * FROM CONTACTS WHERE cusID = " & DropDownList2.SelectedValue
command = New System.Data.SqlClient.SqlCommand(str_sql, connection)
reader = command.ExecuteReader()
If reader.HasRows then
while reader.Read()
FirstName.Text = reader.Item("FirstName").ToString()
LastName.Text = reader.Item("LastName").ToString()
end while
End If
reader.Close()
str_sql = "SELECT * FROM Zip WHERE cusID = " & DropDownList1.SelectedValue
command = New System.Data.SqlClient.SqlCommand(str_sql, connection)
reader = command.ExecuteReader()
If reader.HasRows then
while reader.Read()
City.Text = reader.Item("City").ToString()
State.Text = reader.Item("State").ToString()
Zip.Text = reader.Item("Zip").ToString()
end while
End If
reader.Close()
connection.Close()
Catch
End Try
End Using
else
response.write("2222222222222222222222222")
end if
End Sub
Protected Sub DropDownListEquip_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs)
End Sub
End Class
11111111111111111 displayed at the top of the page above the content
Oh woops, I forgot to change the data LOL.
Here you go:
Partial Class AddCall
Inherits System.Web.UI.Page
Protected Sub DropDownList1_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles DropDownList1.SelectedIndexChanged
Dim FirstName As TextBox = TryCast(FormView1.FindControl("FirstName"), TextBox)
Dim LastName As TextBox = TryCast(FormView1.FindControl("LastName"), TextBox)
DropDownList2.SelectedIndex = 0
FirstName.Text = ""
LastName.Text = ""
End Sub
Protected Sub DropDownList2_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles DropDownList2.SelectedIndexChanged
'labelSelection.Text = DropDownList1.SelectedItem.Text & " " & DropDownList2.SelectedItem.Text
Dim Company As TextBox = TryCast(FormView1.FindControl("Company"), TextBox)
Dim Address1 As TextBox = TryCast(FormView1.FindControl("Address1"), TextBox)
Dim Address2 As TextBox = TryCast(FormView1.FindControl("Address2"), TextBox)
Dim Phone As TextBox = TryCast(FormView1.FindControl("Phone"), TextBox)
Dim FirstName As TextBox = TryCast(FormView1.FindControl("FirstName"), TextBox)
Dim LastName As TextBox = TryCast(FormView1.FindControl("LastName"), TextBox)
Dim City As TextBox = TryCast(FormView1.FindControl("City"), TextBox)
Dim State As TextBox = TryCast(FormView1.FindControl("State"), TextBox)
Dim Zip As TextBox = TryCast(FormView1.FindControl("Zip"), TextBox)
Dim str_sql As String = "SELECT * FROM Customers WHERE cusID = " & DropDownList1.SelectedValue
Using connection As New System.Data.SqlClient.SqlConnection("Data Source=IT-P02\SQLEXPRESS;Initial Catalog=HRIService;Integrated Security=True")
Dim command As New System.Data.SqlClient.SqlCommand(str_sql, connection)
Try
connection.Open()
Dim reader As System.Data.SqlClient.SqlDataReader = command.ExecuteReader()
If reader.HasRows then
while reader.Read()
Company.Text = reader.Item("Company").ToString
Address1.Text = reader.Item("Address1").ToString
Address2.Text = reader.Item("Address2").ToString
Phone.Text = reader.Item("Phone").ToString
end while
End If
reader.Close()
str_sql = "SELECT * FROM CONTACTS WHERE cusID = " & DropDownList2.SelectedValue
command = New System.Data.SqlClient.SqlCommand(str_sql, connection)
reader = command.ExecuteReader()
If reader.HasRows then
while reader.Read()
FirstName.Text = reader.Item("FirstName").ToString()
LastName.Text = reader.Item("LastName").ToString()
end while
End If
reader.Close()
str_sql = "SELECT * FROM Zip WHERE cusID = " & DropDownList1.SelectedValue
command = New System.Data.SqlClient.SqlCommand(str_sql, connection)
reader = command.ExecuteReader()
If reader.HasRows then
while reader.Read()
City.Text = reader.Item("City").ToString()
State.Text = reader.Item("State").ToString()
Zip.Text = reader.Item("Zip").ToString()
end while
End If
reader.Close()
connection.Close()
Catch
End Try
End Using
End Sub
Protected Sub Page_Load(ByVal S As Object, ByVal E As System.EventArgs)
Dim cusID As String = Trim(Request.QueryString("cusID"))
Dim conID As String = Trim(Request.QueryString("conID"))
if Not cusID Is Nothing and Not conID Is Nothing and Len(cusID) > 1 and Len(conID) > 1 then
response.write("1111111111111111111111111")
'labelSelection.Text = DropDownList1.SelectedItem.Text & " " & DropDownList2.SelectedItem.Text
Dim Company As TextBox = TryCast(FormView1.FindControl("Company"), TextBox)
Dim Address1 As TextBox = TryCast(FormView1.FindControl("Address1"), TextBox)
Dim Address2 As TextBox = TryCast(FormView1.FindControl("Address2"), TextBox)
Dim Phone As TextBox = TryCast(FormView1.FindControl("Phone"), TextBox)
Dim FirstName As TextBox = TryCast(FormView1.FindControl("FirstName"), TextBox)
Dim LastName As TextBox = TryCast(FormView1.FindControl("LastName"), TextBox)
Dim City As TextBox = TryCast(FormView1.FindControl("City"), TextBox)
Dim State As TextBox = TryCast(FormView1.FindControl("State"), TextBox)
Dim Zip As TextBox = TryCast(FormView1.FindControl("Zip"), TextBox)
Dim str_sql As String = "SELECT * FROM Customers WHERE cusID=@cusID"
Using connection As New System.Data.SqlClient.SqlConnection("Data Source=IT-P02\SQLEXPRESS;Initial Catalog=HRIService;Integrated Security=True")
Dim command As New System.Data.SqlClient.SqlCommand(str_sql, connection)
command.Parameters.AddWithValue("@cusID", cusID)
Try
connection.Open()
Dim reader As System.Data.SqlClient.SqlDataReader = command.ExecuteReader()
If reader.HasRows then
while reader.Read()
Company.Text = reader.Item("Company").ToString
Address1.Text = reader.Item("Address1").ToString
Address2.Text = reader.Item("Address2").ToString
Phone.Text = reader.Item("Phone").ToString
end while
End If
reader.Close()
str_sql = "SELECT * FROM CONTACTS WHERE conID=@conID"
command.Parameters.AddWithValue("@conID", conID)
command = New System.Data.SqlClient.SqlCommand(str_sql, connection)
reader = command.ExecuteReader()
If reader.HasRows then
while reader.Read()
FirstName.Text = reader.Item("FirstName").ToString()
LastName.Text = reader.Item("LastName").ToString()
end while
End If
reader.Close()
str_sql = "SELECT * FROM Zip WHERE conID=@conID"
command.Parameters.AddWithValue("@conID", conID)
command = New System.Data.SqlClient.SqlCommand(str_sql, connection)
reader = command.ExecuteReader()
If reader.HasRows then
while reader.Read()
City.Text = reader.Item("City").ToString()
State.Text = reader.Item("State").ToString()
Zip.Text = reader.Item("Zip").ToString()
end while
End If
reader.Close()
connection.Close()
DropDownList2.Items.FindByValue(conID).Selected = True
Catch
End Try
End Using
else
response.write("2222222222222222222222222")
end if
End Sub
Protected Sub DropDownListEquip_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs)
End Sub
End Class
Alrighty, getting closer. The Company info was posted in the fields but neither of the ddls were selected and the contact info is blank.
The 1s are showing still, too.
Okay, this should work (hopefully). I must tell you, I hate code behind.
Partial Class AddCall
Inherits System.Web.UI.Page
Protected Sub DropDownList1_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles DropDownList1.SelectedIndexChanged
Dim FirstName As TextBox = TryCast(FormView1.FindControl("FirstName"), TextBox)
Dim LastName As TextBox = TryCast(FormView1.FindControl("LastName"), TextBox)
DropDownList2.SelectedIndex = 0
FirstName.Text = ""
LastName.Text = ""
End Sub
Protected Sub DropDownList2_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles DropDownList2.SelectedIndexChanged
'labelSelection.Text = DropDownList1.SelectedItem.Text & " " & DropDownList2.SelectedItem.Text
Dim Company As TextBox = TryCast(FormView1.FindControl("Company"), TextBox)
Dim Address1 As TextBox = TryCast(FormView1.FindControl("Address1"), TextBox)
Dim Address2 As TextBox = TryCast(FormView1.FindControl("Address2"), TextBox)
Dim Phone As TextBox = TryCast(FormView1.FindControl("Phone"), TextBox)
Dim FirstName As TextBox = TryCast(FormView1.FindControl("FirstName"), TextBox)
Dim LastName As TextBox = TryCast(FormView1.FindControl("LastName"), TextBox)
Dim City As TextBox = TryCast(FormView1.FindControl("City"), TextBox)
Dim State As TextBox = TryCast(FormView1.FindControl("State"), TextBox)
Dim Zip As TextBox = TryCast(FormView1.FindControl("Zip"), TextBox)
Dim str_sql As String = "SELECT * FROM Customers WHERE cusID = " & DropDownList1.SelectedValue
Using connection As New System.Data.SqlClient.SqlConnection("Data Source=IT-P02\SQLEXPRESS;Initial Catalog=HRIService;Integrated Security=True")
Dim command As New System.Data.SqlClient.SqlCommand(str_sql, connection)
Try
connection.Open()
Dim reader As System.Data.SqlClient.SqlDataReader = command.ExecuteReader()
If reader.HasRows then
while reader.Read()
Company.Text = reader.Item("Company").ToString
Address1.Text = reader.Item("Address1").ToString
Address2.Text = reader.Item("Address2").ToString
Phone.Text = reader.Item("Phone").ToString
end while
End If
reader.Close()
str_sql = "SELECT * FROM CONTACTS WHERE cusID = " & DropDownList2.SelectedValue
command = New System.Data.SqlClient.SqlCommand(str_sql, connection)
reader = command.ExecuteReader()
If reader.HasRows then
while reader.Read()
FirstName.Text = reader.Item("FirstName").ToString()
LastName.Text = reader.Item("LastName").ToString()
end while
End If
reader.Close()
str_sql = "SELECT * FROM Zip WHERE cusID = " & DropDownList1.SelectedValue
command = New System.Data.SqlClient.SqlCommand(str_sql, connection)
reader = command.ExecuteReader()
If reader.HasRows then
while reader.Read()
City.Text = reader.Item("City").ToString()
State.Text = reader.Item("State").ToString()
Zip.Text = reader.Item("Zip").ToString()
end while
End If
reader.Close()
connection.Close()
Catch
End Try
End Using
End Sub
Protected Sub Page_Load(ByVal S As Object, ByVal E As System.EventArgs)
Dim cusID As String = Trim(Request.QueryString("cusID"))
Dim conID As String = Trim(Request.QueryString("conID"))
if Not cusID Is Nothing and Not conID Is Nothing and Len(cusID) > 1 and Len(conID) > 1 then
'labelSelection.Text = DropDownList1.SelectedItem.Text & " " & DropDownList2.SelectedItem.Text
Dim Company As TextBox = TryCast(FormView1.FindControl("Company"), TextBox)
Dim Address1 As TextBox = TryCast(FormView1.FindControl("Address1"), TextBox)
Dim Address2 As TextBox = TryCast(FormView1.FindControl("Address2"), TextBox)
Dim Phone As TextBox = TryCast(FormView1.FindControl("Phone"), TextBox)
Dim FirstName As TextBox = TryCast(FormView1.FindControl("FirstName"), TextBox)
Dim LastName As TextBox = TryCast(FormView1.FindControl("LastName"), TextBox)
Dim City As TextBox = TryCast(FormView1.FindControl("City"), TextBox)
Dim State As TextBox = TryCast(FormView1.FindControl("State"), TextBox)
Dim Zip As TextBox = TryCast(FormView1.FindControl("Zip"), TextBox)
Dim str_sql As String = "SELECT * FROM Customers WHERE cusID=@cusID"
Using connection As New System.Data.SqlClient.SqlConnection("Data Source=IT-P02\SQLEXPRESS;Initial Catalog=HRIService;Integrated Security=True")
Dim command As New System.Data.SqlClient.SqlCommand(str_sql, connection)
command.Parameters.AddWithValue("@cusID", cusID)
Try
connection.Open()
Dim reader As System.Data.SqlClient.SqlDataReader = command.ExecuteReader()
If reader.HasRows then
while reader.Read()
Company.Text = reader.Item("Company").ToString
Address1.Text = reader.Item("Address1").ToString
Address2.Text = reader.Item("Address2").ToString
Phone.Text = reader.Item("Phone").ToString
end while
End If
reader.Close()
str_sql = "SELECT * FROM CONTACTS WHERE conID=@conID"
command.Parameters.AddWithValue("@conID", conID)
command = New System.Data.SqlClient.SqlCommand(str_sql, connection)
reader = command.ExecuteReader()
If reader.HasRows then
while reader.Read()
FirstName.Text = reader.Item("FirstName").ToString()
LastName.Text = reader.Item("LastName").ToString()
end while
End If
reader.Close()
str_sql = "SELECT * FROM Zip WHERE cusID=@cusID"
command.Parameters.AddWithValue("@cusID", cusID)
command = New System.Data.SqlClient.SqlCommand(str_sql, connection)
reader = command.ExecuteReader()
If reader.HasRows then
while reader.Read()
City.Text = reader.Item("City").ToString()
State.Text = reader.Item("State").ToString()
Zip.Text = reader.Item("Zip").ToString()
end while
End If
reader.Close()
connection.Close()
DropDownList1.SelectedIndex = DropDownList1.Items.IndexOf(DropDownList1.Items.FindByValue(cusID))
DropDownList2.SelectedIndex = DropDownList2.Items.IndexOf(DropDownList2.Items.FindByValue(conID))
Catch
End Try
End Using
end if
End Sub
Protected Sub DropDownListEquip_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs)
End Sub
End Class
Check to make sure that the parameters in red are the correct ones in your database (how they are spelled, (cusID or conID || customerID or contactID). Change them accordingly. The code is there, but it is not receiving the correct information to relate it to a record.
Code behind is good for you. It's recommended by 2 out of 3 programmers.:)
contactID is what I have for the primary key in the Contacts table. Although, it didn't like something about that.
Server Error in '/HRIService' Application.
Compilation Error
Description: An error occurred during the compilation of a resource required to service this request. Please review the following specific error details and modify your source code appropriately.
Compiler Error Message: BC30451: Name 'contactID' is not declared.
Source Error:
Line 119:
Line 120: str_sql = "SELECT * FROM CONTACTS WHERE contactID=@contactID"
Line 121: command.Parameters.AddWithValue("@contactID", contactID)
Line 122: command = New System.Data.SqlClient.SqlCommand(str_sql, connection)
Line 123: reader = command.ExecuteReader()
Source File: C:\Inetpub\wwwroot\HRIService\ServiceExpress\AddCall.aspx.vb Line: 121
You cannot change ContactID, it's set as conID.
Just change this:
command.Parameters.AddWithValue("@contactID", conID)
Same result as last time. No ddls were populated.
Hey, can I rewrite your entire thing, including the aspx page?
I guess so if this the way it is currently set up is not going to work the way it needs to. What do you need? By the way the end result of this page is to insert a new ticket into the Dispatch table and when that happens it redirects to the Dispatch View page which show all the active tickets.
Make sure I have this correctly, and give me an updated table list:
View 1:
User Views this page and chooses his/her company. Then chooses his/her contact. Then selects the appropriate equipment and posts a ticket. This then ads the ticket into the Dispatch table and redirects to the Dispatch view page.
- I need the name of the dispatch view page.
View 2:
User creates the company or contact from the last page, which redirects to this page with the customer ID and the contact ID. Then the page is pre-filled out according to this data.
If this is all correct, let me know and tell me the updated table list with all the columns and the name of the dispatch view page.
This won't take me long, but will take me much longer trying to head through your code ^^
Yes, that is correct. The view page is Dispatch.aspx. The main add ticket page is AddCall.aspx, and the secondary add company/contact page is DisAddCo.aspx
Here are the tables and columns:
Customers
cusID
Company
Address1
Address2
Country
POBox
Phone
Fax
Website
HRIRep
Contacts
contactID
cusID
FirstName
LastName
Title
Equipment
eqpID
mfgID
ModelNumber
Description
MeterLocation
Manufacturers
mfgID
Company
Equipment (y/n)
Supplies (y/n)
Parts (y/n)
Address1
Address2
Phone
Fax
Contact
WarrantyTime
Cus_Equip
cuseqpID
SerialNumber
eqpID
mfgID
Zip
cusID
City
State
Zip
Dispatch
disID
cusID
userID
Problem
Status
Contract
Priority
ScheduleTime
DispatchEvents
eventID
disID
DateTime
Actions
Notes
Users
userID
Username
Password
Userlevel
FirstName
LastName
Role
Active
Contract
Equipment
Parts
Dispatch
Except for this right:
Cus_Equip
cuseqpID
SerialNumber
eqpID
mfgID -> cusID
Yes, that is correct. Its supposed to be cusID. You caught me. I copied it and missed that.
ASPX File:
<%@ Page Language="VB" MasterPageFile="~/MasterPage.master" AutoEventWireup="false" CodeFile="AddCall.aspx.vb" Inherits="AddCall" title="Hackworth Reprographics Service Express - Add Call" %>
<asp:Content ID="Content1" ContentPlaceHolderID="head" Runat="Server">
<style type="text/css">
.style5
{
font-family: Verdana;
font-size: 12px;
color: #000000;
text-align: left;
font-weight: bold;
}
.style6 { height: 20px; }
.style7 { }
.style8 { }
.style9 { width: 26px; }
.style10 { width: 79px; }
.style11 { width: 134px; }
.style12 { width: 50px; }
.style13 { width: 40px; }
.style14 { width: 149px; }
.style15 { width: 86px; }
.style16
{
width: 86px;
height: 22px;
}
.style17
{
width: 149px;
height: 22px;
}
.style18
{
width: 40px;
height: 22px;
}
.style19
{
width: 50px;
height: 22px;
}
.style20
{
width: 26px;
height: 22px;
}
.style21
{
width: 134px;
height: 22px;
}
.style22
{
width: 79px;
height: 22px;
}
.style23 { height: 22px; }
</style>
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" Runat="Server">
<table width="100%" cellpadding="0" cellspacing="0" class="topblack">
<tr>
<td width="177px" class="rightborder" bgcolor="#CCCCCC" valign="top">
<asp:TreeView ID="TreeView1" runat="server" DataSourceID="SiteMapDataSource1"
ImageSet="Arrows" style="text-align: left">
<ParentNodeStyle Font-Bold="False" />
<HoverNodeStyle Font-Underline="True" ForeColor="Maroon" />
<SelectedNodeStyle Font-Underline="True" ForeColor="Maroon"
HorizontalPadding="0px" VerticalPadding="0px" />
<NodeStyle Font-Names="Tahoma" Font-Size="10pt" ForeColor="Black"
HorizontalPadding="5px" NodeSpacing="0px" VerticalPadding="0px" />
</asp:TreeView>
<br />
</td>
<td valign="top">
<table cellspacing="2" cellpadding="0" width="100%">
<tr>
<td>
<div align="left"><asp:SiteMapPath ID="SiteMapPath1" runat="server" PathSeparator=" | ">
<CurrentNodeStyle CssClass="header" Font-Underline="False" ForeColor="Black" />
<NodeStyle CssClass="header" ForeColor="#990000" />
<RootNodeStyle CssClass="header" ForeColor="Maroon" />
</asp:SiteMapPath></div>
</td>
<td>
<div align="right"> <asp:LoginStatus ID="LoginStatus1" runat="server" CssClass="maintext" />
</div></td>
</tr>
<tr>
<td colspan="2" style="text-align: left">
<table align="center" cellpadding="0" class="style2" style="width: 99%">
<tr>
<td>
<table cellpadding="0" class="style2">
<tr>
<td>
</td>
</tr>
<tr>
<td>
<span class="style5">Select a Company:</span>
<asp:DropDownList
ID="DropDownList1"
runat="server"
CssClass="maintext"
ForeColor="Maroon"
AutoPostBack="True" />
</td>
</tr>
<tr>
<td
<span class="maintext"><b>Select a Contact:</b> </span>
<asp:DropDownList
ID="DropDownList2"
runat="server"
CssClass="maintext"
ForeColor="Maroon"
AutoPostBack="True" />
<asp:Label ID="labelSelection"
runat="server" style="z-index: 102; left: 368px; position: absolute; top: 144px">
</asp:Label>
</td>
</tr>
<tr>
<td class="style6">
<asp:HyperLink
ID="AddCompany"
runat="server"
CssClass="maintext"
Font-Bold="True"
ForeColor="Maroon"
NavigateUrl="~/ServiceExpress/DisAddCo.aspx">Add New Company?</asp:HyperLink>
<br />
<br />
<asp:FormView ID="FormView1" runat="server" DefaultMode="Insert"
DataSourceID="SqlDataSource4">
<InsertItemTemplate>
<table cellpadding="0" class="style2">
<tr>
<td class="maintext">
Company:</td>
<td colspan="5" style="margin-left: 40px">
<asp:TextBox ID="Company" runat="server" Width="250px" ReadOnly="True"></asp:TextBox>
</td>
<td class="maintext">
Phone:</td>
<td>
<asp:TextBox ID="Phone" runat="server" ReadOnly="True"></asp:TextBox>
</td>
</tr>
<tr>
<td class="maintext">
First Name:</td>
<td colspan="5">
<asp:TextBox ID="FirstName" runat="server" Width="200px" ReadOnly="True"></asp:TextBox>
</td>
<td class="style10">
</td>
<td>
</td>
</tr>
<tr>
<td class="maintext">
Last Name:
</td>
<td colspan="5">
<asp:TextBox ID="LastName" runat="server" style="margin-bottom: 0px"
Width="200px" ReadOnly="True"></asp:TextBox>
</td>
<td class="maintext">
Technician:</td>
<td>
<asp:DropDownList ID="DropDownListTech" runat="server" CssClass="maintext"
DataSourceID="SqlDataSource3" DataTextField="techid"
DataValueField="UserID" AppendDataBoundItems="True">
<asp:ListItem Value="">Unassigned</asp:ListItem>
</asp:DropDownList>
</td>
</tr>
<tr>
<td class="maintext">
Address:</td>
<td colspan="5">
<asp:TextBox ID="Address1" runat="server" Width="200px" ReadOnly="True"></asp:TextBox>
</td>
<td class="maintext">
Priority:</td>
<td>
<asp:DropDownList ID="DropDownListPriority" runat="server" CssClass="maintext">
<asp:ListItem Selected="True">Select One</asp:ListItem>
<asp:ListItem>Red (High)</asp:ListItem>
<asp:ListItem>Yellow</asp:ListItem>
<asp:ListItem>Blue</asp:ListItem>
<asp:ListItem>Green (Low)</asp:ListItem>
</asp:DropDownList>
</td>
</tr>
<tr>
<td class="style15">
</td>
<td colspan="5">
<asp:TextBox ID="Address2" runat="server" Width="200px"
style="margin-bottom: 0px" ReadOnly="True"></asp:TextBox>
</td>
<td class="maintext">
Billing:</td>
<td>
<asp:DropDownList ID="DropDownListBill" runat="server" CssClass="maintext">
<asp:ListItem Selected="True">Select One</asp:ListItem>
<asp:ListItem>Contract</asp:ListItem>
<asp:ListItem>Time/Materials</asp:ListItem>
</asp:DropDownList>
</td>
</tr>
<tr>
<td class="maintext">
City:</td>
<td class="style14">
<asp:TextBox ID="City" runat="server" ReadOnly="True"></asp:TextBox>
</td>
<td class="maintext">
State:</td>
<td class="style12">
<asp:TextBox ID="State" runat="server" Width="30px" ReadOnly="True"></asp:TextBox>
</td>
<td class="maintext">
Zip:</td>
<td class="style11">
<asp:TextBox ID="Zip" runat="server" Width="80px" ReadOnly="True"></asp:TextBox>
</td>
<td class="style10">
</td>
<td>
</td>
</tr>
<tr>
<td class="style16">
</td>
<td class="style17">
</td>
<td class="style18">
</td>
<td class="style19">
</td>
<td class="style20">
</td>
<td class="style21">
</td>
<td class="style22">
</td>
<td class="style23">
</td>
</tr>
<tr>
<td class="maintext">
Equipment:</td>
<td class="style14">
<asp:DropDownList ID="DropDownListEquip" runat="server" CssClass="maintext" />
</td>
<td class="style13">
</td>
<td class="style12">
</td>
<td class="style9">
</td>
<td class="style11">
</td>
<td class="style10">
</td>
<td>
</td>
</tr>
<tr>
<td class="maintext" valign="top">
Problem:</td>
<td class="style8" colspan="5">
<asp:TextBox ID="Problem" runat="server" Height="100px" TextMode="MultiLine"
Width="400px"></asp:TextBox>
</td>
<td class="maintext" valign="top">
Notes:</td>
<td>
<asp:TextBox ID="Notes" runat="server" Height="100px" TextMode="MultiLine"
Width="400px"></asp:TextBox>
</td>
</tr>
<tr>
<td class="style7" colspan="8" valign="top">
<asp:Button ID="Button1" runat="server" Text="Submit" />
<asp:Button ID="Button2" runat="server" Text="Reset" />
</td>
</tr>
</table>
</InsertItemTemplate>
</asp:FormView>
<br />
<br />
</td>
</tr>
</table>
</td>
</tr>
</table>
<asp:SqlDataSource
ID="SqlDataSource3"
runat="server"
ConnectionString="<%$ ConnectionStrings:HRIServiceConnectionString1 %>"
SelectCommand="SELECT [UserID], [FirstName]+ ' ' + [LastName] AS techid FROM [aspnet_Users] WHERE [isTech] = 'True' ORDER BY [LastName], [FirstName]">
</asp:SqlDataSource>
</td>
</tr>
</table>
<asp:SiteMapDataSource ID="SiteMapDataSource1" runat="server" />
</td>
</tr>
</table>
</asp:Content>
Code-Behind:
Partial Class AddCall
Inherits System.Web.UI.Page
Dim conn As New System.Data.SqlClient.SqlConnection(ConfigurationManager.ConnectionStrings("HRIServiceConnectionString1")
Dim cmd As System.Data.SqlClient.SqlCommand
Dim reader As System.Data.SqlClient.SqlDataReader = command.ExecuteReader()
Protected Sub Page_Load(ByVal S As Object, ByVal E As System.EventArgs)
If Not Page.IsPostBack Then
Dim bol As Boolean = False
Dim conID As String = Trim(Request.QueryString("conID")).ToString()
Dim cusID As String = Trim(Request.QueryString("cusID")).ToString()
If Len(cusID) > 0 And Len(conID) > 0 Then
Dim FirstName As TextBox = TryCast(FormView1.FindControl("FirstName"), TextBox)
Dim LastName As TextBox = TryCast(FormView1.FindControl("LastName"), TextBox)
Dim Company As TextBox = TryCast(FormView1.FindControl("Company"), TextBox)
Dim Address1 As TextBox = TryCast(FormView1.FindControl("Address1"), TextBox)
Dim Address2 As TextBox = TryCast(FormView1.FindControl("Address2"), TextBox)
Dim Phone As TextBox = TryCast(FormView1.FindControl("Phone"), TextBox)
Dim FirstName As TextBox = TryCast(FormView1.FindControl("FirstName"), TextBox)
Dim LastName As TextBox = TryCast(FormView1.FindControl("LastName"), TextBox)
Dim City As TextBox = TryCast(FormView1.FindControl("City"), TextBox)
Dim State As TextBox = TryCast(FormView1.FindControl("State"), TextBox)
Dim Zip As TextBox = TryCast(FormView1.FindControl("Zip"), TextBox)
Try
cmd = New System.Data.SqlClient.SqlCommand("SELECT cusID, FirstName+ ' ' + LastName AS ContactName FROM Contacts WHERE cusID=@cusID ORDER BY LastName, FirstName", conn)
cmd.Parameters.AddWithValue("@cusID", cusID)
conn.Open()
reader = cmd.ExecuteReader()
If reader.HasRows Then
DropDownList2.DataSource = reader
DropDownList2.DataTextField = "ContactName"
DropDownList2.DataValueField = "cusID"
DropDownList2.DataBind()
DropDownList2.Items.Insert(0, ("-- Choose a Contact --"))
DropDownList2.Items.IndexOf(DropDownList2.Items.FindByValue(conID))
Else
DropDownList2.Items.Insert(0, ("-- Error: No Contacts Found --")
End If
reader.Close()
cmd = New System.Data.SqlClient.SqlCommand("SELECT a.Company, a.Address1, a.Address2, b.FirstName, b.LastName, c.City, c.State, c.Zip FROM Customers a JOIN Contacts b ON a.cusID=b.cusID JOIN Zip c ON a.cusID=c.cusID WHERE a.cusID=@cusID and b.ContactID=@conID", conn)
cmd.Parameters.AddWithValue("@cusID", cusID)
cmd.Parameters.AddWithValue("@ContactID", conID)
reader = command.ExecuteReader()
If reader.HasRows Then
While reader.Read()
Company.Text = reader.Item("Company").ToString
Address1.Text = reader.Item("Address1").ToString
Address2.Text = reader.Item("Address2").ToString
Phone.Text = reader.Item("Phone").ToString
FirstName.Text = reader.Item("FirstName").ToString()
LastName.Text = reader.Item("LastName").ToString()
City.Text = reader.Item("City").ToString()
State.Text = reader.Item("State").ToString()
Zip.Text = reader.Item("Zip").ToString()
End While
End If
reader.Close()
Catch
End Try
bol = True
End If
cmd = New System.Data.SqlClient.SqlCommand("SELECT cusID, Company FROM Customers", conn)
Try
If Not conn.State = ConnectionState.Open Then conn.Open()
reader = cmd.ExecuteReader()
If reader.HasRows Then
DropDownList1.DataSource = reader
DropDownList1.DataTextField = "Company"
DropDownList1.DataValueField = "cusID"
DropDownList1.DataBind()
DropDownList1.Items.Insert(0, ("-- Choose a Company --"))
If bol = True Then DropDownList1.Items.IndexOf(DropDownList1.Items.FindByValue(conID).ToString()))
Else
DropDownList1.Items.Insert(0, ("-- Error: No Companies Found --")
End If
reader.Close()
conn.Close()
Catch
End Try
If conn.State = ConnectionState.Open Then conn.Close()
End If
End Sub
Protected Sub DropDownList1_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles DropDownList1.SelectedIndexChanged
Dim FirstName As TextBox = TryCast(FormView1.FindControl("FirstName"), TextBox)
Dim LastName As TextBox = TryCast(FormView1.FindControl("LastName"), TextBox)
Try
cmd = New System.Data.SqlClient.SqlCommand("SELECT cusID, FirstName+ ' ' + LastName AS ContactName FROM Contacts WHERE cusID=@cusID ORDER BY LastName, FirstName", conn)
cmd.Parameters.AddWithValue("@cusID", DropDownList1.SelectedValue)
conn.Open()
reader = cmd.ExecuteReader()
If reader.HasRows Then
DropDownList2.DataSource = reader
DropDownList2.DataTextField = "ContactName"
DropDownList2.DataValueField = "cusID"
DropDownList2.DataBind()
DropDownList2.Items.Insert(0, ("-- Choose a Contact --"))
Else
DropDownList2.Items.Insert(0, ("-- Error: No Contacts Found --")
End If
reader.Close()
cmd = New System.Data.SqlClient.SqlCommand("SELECT a.Company + ' - ' + b.Description As CompanyEqpDesc, b.eqpID FROM Manufacturers a JOIN Equipment b ON a.mfgID=b.mfgID WHERE b.eqpID IN (SELECT eqpID FROM Cus_Equip WHERE cusID=@cusID", conn)
cmd.Parameters.AddWithValue("@cusID", DropDownList1.SelectedValue)
reader = cmd.ExecuteReader()
If reader.HasRows Then
DropDownListEquip.DataSource = reader
DropDownListEquip.DataTextField = "CompanyEqpDesc"
DropDownListEquip.DataValueField = "eqpID"
DropDownListEquip.DataBind()
DropDownListEquip.Items.Insert(0, ("-- Choose Equipment --"))
Else
DropDownListEquip.Items.Insert(0, ("-- Error: No Equipment Found --")
End If
reader.Close()
conn.Close()
Catch
End Try
FirstName.Text = ""
LastName.Text = ""
End Sub
Protected Sub DropDownList2_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles DropDownList2.SelectedIndexChanged
Dim Company As TextBox = TryCast(FormView1.FindControl("Company"), TextBox)
Dim Address1 As TextBox = TryCast(FormView1.FindControl("Address1"), TextBox)
Dim Address2 As TextBox = TryCast(FormView1.FindControl("Address2"), TextBox)
Dim Phone As TextBox = TryCast(FormView1.FindControl("Phone"), TextBox)
Dim FirstName As TextBox = TryCast(FormView1.FindControl("FirstName"), TextBox)
Dim LastName As TextBox = TryCast(FormView1.FindControl("LastName"), TextBox)
Dim City As TextBox = TryCast(FormView1.FindControl("City"), TextBox)
Dim State As TextBox = TryCast(FormView1.FindControl("State"), TextBox)
Dim Zip As TextBox = TryCast(FormView1.FindControl("Zip"), TextBox)
cmd = New System.Data.SqlClient.SqlCommand("SELECT a.Company, a.Address1, a.Address2, b.FirstName, b.LastName, c.City, c.State, c.Zip FROM Customers a JOIN Contacts b ON a.cusID=b.cusID JOIN Zip c ON a.cusID=c.cusID WHERE a.cusID=" & DropDownList1.SelectedValue, conn)
Try
conn.Open()
reader = command.ExecuteReader()
If reader.HasRows Then
While reader.Read()
Company.Text = reader.Item("Company").ToString
Address1.Text = reader.Item("Address1").ToString
Address2.Text = reader.Item("Address2").ToString
Phone.Text = reader.Item("Phone").ToString
FirstName.Text = reader.Item("FirstName").ToString()
LastName.Text = reader.Item("LastName").ToString()
City.Text = reader.Item("City").ToString()
State.Text = reader.Item("State").ToString()
Zip.Text = reader.Item("Zip").ToString()
End While
End If
reader.Close()
conn.Close()
Catch
End Try
End Sub
End Class
Oh damn, I forgot to add the "add record" thingy. I'll give you a new update in a moment.
A couple of things.. what are you doing with the field "Notes", and where are you storing the EqpID? Neither have places to go.
Also, Status?
And where's userid?
Notes goes into Dispatch Events. That table is there to track any update to each ticket that has been created. When you view the ticket detail it will give you the history of that ticket ie: open, on hold, etc.
EqpID may not be necessary. When I created the db I was under the assumption each table needed a primary key.
updating..
Also, the Notes will be a field that will be updated each time the ticket is updated. So, it will clear out after each update. And it will show only in the ticket history details.
Updated:
Partial Class AddCall
Inherits System.Web.UI.Page
Dim conn As New System.Data.SqlClient.SqlConnection(ConfigurationManager.ConnectionStrings("HRIServiceConnectionString1")
Dim cmd As System.Data.SqlClient.SqlCommand
Dim reader As System.Data.SqlClient.SqlDataReader = command.ExecuteReader()
Protected Sub Page_Load(ByVal S As Object, ByVal E As System.EventArgs)
If Not Page.IsPostBack Then
Dim bol As Boolean = False
Dim conID As String = Trim(Request.QueryString("conID")).ToString()
Dim cusID As String = Trim(Request.QueryString("cusID")).ToString()
If Len(cusID) > 0 And Len(conID) > 0 Then
Dim FirstName As TextBox = TryCast(FormView1.FindControl("FirstName"), TextBox)
Dim LastName As TextBox = TryCast(FormView1.FindControl("LastName"), TextBox)
Dim Company As TextBox = TryCast(FormView1.FindControl("Company"), TextBox)
Dim Address1 As TextBox = TryCast(FormView1.FindControl("Address1"), TextBox)
Dim Address2 As TextBox = TryCast(FormView1.FindControl("Address2"), TextBox)
Dim Phone As TextBox = TryCast(FormView1.FindControl("Phone"), TextBox)
Dim FirstName As TextBox = TryCast(FormView1.FindControl("FirstName"), TextBox)
Dim LastName As TextBox = TryCast(FormView1.FindControl("LastName"), TextBox)
Dim City As TextBox = TryCast(FormView1.FindControl("City"), TextBox)
Dim State As TextBox = TryCast(FormView1.FindControl("State"), TextBox)
Dim Zip As TextBox = TryCast(FormView1.FindControl("Zip"), TextBox)
Try
cmd = New System.Data.SqlClient.SqlCommand("SELECT cusID, FirstName+ ' ' + LastName AS ContactName FROM Contacts WHERE cusID=@cusID ORDER BY LastName, FirstName", conn)
cmd.Parameters.AddWithValue("@cusID", cusID)
conn.Open()
reader = cmd.ExecuteReader()
If reader.HasRows Then
DropDownList2.DataSource = reader
DropDownList2.DataTextField = "ContactName"
DropDownList2.DataValueField = "cusID"
DropDownList2.DataBind()
DropDownList2.Items.Insert(0, ("-- Choose a Contact --"))
DropDownList2.Items.IndexOf(DropDownList2.Items.FindByValue(conID))
Else
DropDownList2.Items.Insert(0, ("-- Error: No Contacts Found --")
End If
reader.Close()
cmd = New System.Data.SqlClient.SqlCommand("SELECT a.Company, a.Address1, a.Address2, b.FirstName, b.LastName, c.City, c.State, c.Zip FROM Customers a JOIN Contacts b ON a.cusID=b.cusID JOIN Zip c ON a.cusID=c.cusID WHERE a.cusID=@cusID and b.ContactID=@conID", conn)
cmd.Parameters.AddWithValue("@cusID", cusID)
cmd.Parameters.AddWithValue("@ContactID", conID)
reader = command.ExecuteReader()
If reader.HasRows Then
While reader.Read()
Company.Text = reader.Item("Company").ToString
Address1.Text = reader.Item("Address1").ToString
Address2.Text = reader.Item("Address2").ToString
Phone.Text = reader.Item("Phone").ToString
FirstName.Text = reader.Item("FirstName").ToString()
LastName.Text = reader.Item("LastName").ToString()
City.Text = reader.Item("City").ToString()
State.Text = reader.Item("State").ToString()
Zip.Text = reader.Item("Zip").ToString()
End While
End If
reader.Close()
Catch
End Try
bol = True
End If
cmd = New System.Data.SqlClient.SqlCommand("SELECT cusID, Company FROM Customers", conn)
Try
If Not conn.State = ConnectionState.Open Then conn.Open()
reader = cmd.ExecuteReader()
If reader.HasRows Then
DropDownList1.DataSource = reader
DropDownList1.DataTextField = "Company"
DropDownList1.DataValueField = "cusID"
DropDownList1.DataBind()
DropDownList1.Items.Insert(0, ("-- Choose a Company --"))
If bol = True Then DropDownList1.Items.IndexOf(DropDownList1.Items.FindByValue(conID).ToString()))
Else
DropDownList1.Items.Insert(0, ("-- Error: No Companies Found --")
End If
reader.Close()
conn.Close()
Catch
End Try
If conn.State = ConnectionState.Open Then conn.Close()
End If
End Sub
Protected Sub DropDownList1_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles DropDownList1.SelectedIndexChanged
Dim FirstName As TextBox = TryCast(FormView1.FindControl("FirstName"), TextBox)
Dim LastName As TextBox = TryCast(FormView1.FindControl("LastName"), TextBox)
Try
cmd = New System.Data.SqlClient.SqlCommand("SELECT cusID, FirstName+ ' ' + LastName AS ContactName FROM Contacts WHERE cusID=@cusID ORDER BY LastName, FirstName", conn)
cmd.Parameters.AddWithValue("@cusID", DropDownList1.SelectedValue)
conn.Open()
reader = cmd.ExecuteReader()
If reader.HasRows Then
DropDownList2.DataSource = reader
DropDownList2.DataTextField = "ContactName"
DropDownList2.DataValueField = "cusID"
DropDownList2.DataBind()
DropDownList2.Items.Insert(0, ("-- Choose a Contact --"))
Else
DropDownList2.Items.Insert(0, ("-- Error: No Contacts Found --")
End If
reader.Close()
cmd = New System.Data.SqlClient.SqlCommand("SELECT a.Company + ' - ' + b.Description As CompanyEqpDesc, b.eqpID FROM Manufacturers a JOIN Equipment b ON a.mfgID=b.mfgID WHERE b.eqpID IN (SELECT eqpID FROM Cus_Equip WHERE cusID=@cusID", conn)
cmd.Parameters.AddWithValue("@cusID", DropDownList1.SelectedValue)
reader = cmd.ExecuteReader()
If reader.HasRows Then
DropDownListEquip.DataSource = reader
DropDownListEquip.DataTextField = "CompanyEqpDesc"
DropDownListEquip.DataValueField = "eqpID"
DropDownListEquip.DataBind()
DropDownListEquip.Items.Insert(0, ("-- Choose Equipment --"))
Else
DropDownListEquip.Items.Insert(0, ("-- Error: No Equipment Found --")
End If
reader.Close()
conn.Close()
Catch
End Try
FirstName.Text = ""
LastName.Text = ""
End Sub
Protected Sub DropDownList2_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles DropDownList2.SelectedIndexChanged
Dim Company As TextBox = TryCast(FormView1.FindControl("Company"), TextBox)
Dim Address1 As TextBox = TryCast(FormView1.FindControl("Address1"), TextBox)
Dim Address2 As TextBox = TryCast(FormView1.FindControl("Address2"), TextBox)
Dim Phone As TextBox = TryCast(FormView1.FindControl("Phone"), TextBox)
Dim FirstName As TextBox = TryCast(FormView1.FindControl("FirstName"), TextBox)
Dim LastName As TextBox = TryCast(FormView1.FindControl("LastName"), TextBox)
Dim City As TextBox = TryCast(FormView1.FindControl("City"), TextBox)
Dim State As TextBox = TryCast(FormView1.FindControl("State"), TextBox)
Dim Zip As TextBox = TryCast(FormView1.FindControl("Zip"), TextBox)
cmd = New System.Data.SqlClient.SqlCommand("SELECT a.Company, a.Address1, a.Address2, b.FirstName, b.LastName, c.City, c.State, c.Zip FROM Customers a JOIN Contacts b ON a.cusID=b.cusID JOIN Zip c ON a.cusID=c.cusID WHERE a.cusID=" & DropDownList1.SelectedValue, conn)
Try
conn.Open()
reader = command.ExecuteReader()
If reader.HasRows Then
While reader.Read()
Company.Text = reader.Item("Company").ToString
Address1.Text = reader.Item("Address1").ToString
Address2.Text = reader.Item("Address2").ToString
Phone.Text = reader.Item("Phone").ToString
FirstName.Text = reader.Item("FirstName").ToString()
LastName.Text = reader.Item("LastName").ToString()
City.Text = reader.Item("City").ToString()
State.Text = reader.Item("State").ToString()
Zip.Text = reader.Item("Zip").ToString()
End While
End If
reader.Close()
conn.Close()
Catch
End Try
End Sub
Protected Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim disID As String
Dim recs As Integer = 0
cmd = New System.Data.SqlClient.SqlCommand("INSERT INTO Dispatch (cusID, Problem, Priority, Contract) VALUES (@cusID, @Problem, @Priority, @Contract); SELECT SCOPE_IDENTITY()", conn)
cmd.Parameters.AddWithValue("@cusID", DropDownList1.SelectedValue)
cmd.Parameters.AddWithValue("@Problem", Trim(Problem.Text))
cmd.Parameters.AddWithValue("@Priority", DropDownListPriority.SelectedText)
cmd.Parameters.AddWithValue("@Contract", DropDownListBill.SelectedText)
Try
conn.Open()
disID = cmd.ExecuteScalar()
cmd = New System.Data.SqlClient.SqlCommand("INSERT INTO DispatchEvents (disID, Notes) VALUES (@disID, @Notes)", conn)
cmd.Parameters.AddWithValue("@disID", disID)
cmd.Parameters.AddWithValue("@Notes", Trim(Notes.Text))
recs = cmd.ExecuteNonQuery()
conn.Close()
Catch ex As System.Data.SqlClient.SqlException
End Try
If Len(disID) > 0 Then recs += 1
If recs > 1 Then
Response.Redirect("Dispatch.aspx")
Else
Response.Write("No records inserted (recs counted: " & recs & ").<br /><br />Problem:<br />")
Response.Write(ex)
End If
End Sub
End Class
I haven't tested it yet, but I see a lot of underline errors in the intellisense.
Then grab them. I am using notepad, so I may have errors ^^
We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.