Hi All..
I just moved over to VS.net and trying to design an application using ASP.net. I am having some trouble with the
DropDownList.
1. The event SelectedItemChanged doesnot fire.
2. I used a button and this also reloads the page. I am sure there are some tags I missed.
Any help is appriciated.
thanks
Sid
heres my code:
--------------------------------------------------------------
Imports System.Data.SqlClient
Public Class updateBuild
Inherits System.Web.UI.Page
' Dim DdlSerials As New System.Web.UI.WebControls.DropDownList
'Public Event ListChanged(ByVal sender As Object, ByVal e As EventArgs)
#Region " Web Form Designer Generated Code "
'This call is required by the Web Form Designer.
<System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
Me.SqlConn = New System.Data.SqlClient.SqlConnection
Me.SqlComm = New System.Data.SqlClient.SqlCommand
'
'SqlConn
'
Me.SqlConn.ConnectionString = "workstation id=ASPSERVER;packet size=4096;integrated security=SSPI;data source=AS" & _
"PSERVER;persist security info=False;initial catalog=PCTracker"
'
'SqlComm
'
Me.SqlComm.CommandText = "SELECT PCData.* FROM PCData WHERE (SerialNO = @SerialNo) OR (SONo = @SONo)"
Me.SqlComm.Connection = Me.SqlConn
Me.SqlComm.Parameters.Add(New System.Data.SqlClient.SqlParameter("@SerialNo", System.Data.SqlDbType.NVarChar, 50, "SerialNO"))
Me.SqlComm.Parameters.Add(New System.Data.SqlClient.SqlParameter("@SONo", System.Data.SqlDbType.NVarChar, 50, "SONo"))
End Sub
Protected WithEvents Table1 As System.Web.UI.HtmlControls.HtmlTable
Protected WithEvents tbxSerialNumber As System.Web.UI.WebControls.TextBox
Protected WithEvents tbxSalesOrderNo As System.Web.UI.WebControls.TextBox
Protected WithEvents Button1 As System.Web.UI.WebControls.Button
Protected WithEvents SqlConn As System.Data.SqlClient.SqlConnection
Protected WithEvents SqlComm As System.Data.SqlClient.SqlCommand
Protected WithEvents lblErrorMsg As System.Web.UI.WebControls.Label
Protected WithEvents plhSelect As System.Web.UI.WebControls.PlaceHolder
Protected WithEvents lblText As System.Web.UI.WebControls.Label
Protected WithEvents DgrRecord As System.Web.UI.WebControls.DataGrid
Protected WithEvents DdlSerials As System.Web.UI.WebControls.DropDownList
Protected WithEvents Button2 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
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
AddHandler DdlSerials.SelectedIndexChanged, AddressOf DdlSerials_SelectedIndexChanged
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim SqlDS As New DataSet
Dim SqlDV As New DataView
' Dim DdlSerials As New DropDownList
If tbxSerialNumber.Text = "" And tbxSalesOrderNo.Text = "" Then
lblErrorMsg.Text = " Enter Atleast one value"
Else
' Response.Write("IN ELSE")
Try
SqlConn.Open()
SqlComm.Parameters("@SerialNo").Value = CStr(tbxSerialNumber.Text)
SqlComm.Parameters("@SONo").Value = CStr(tbxSalesOrderNo.Text)
Dim SqlAdapter As New SqlDataAdapter
SqlAdapter.SelectCommand = SqlComm
SqlAdapter.Fill(SqlDS)
'SqlDV.RowFilter = "SerialNO = '" & CStr(tbxSalesOrderNo.Text) & "'"
'Response.Write(SqlDV.Count)
SqlConn.Close()
If SqlDS.Tables(0).Rows.Count = 0 Then
lblText.Text = "No Records found"
Else
If SqlDS.Tables(0).Rows.Count = 1 Then
lblText.Text = "1 match"
Else
If SqlDS.Tables(0).Rows.Count > 1 Then
lblText.Text = SqlDS.Tables(0).Rows.Count & " records found"
DdlSerials.Items.Clear()
DdlSerials.Visible = True
' DdlSerials.AutoPostBack = False
DdlSerials.DataTextField = "SerialNo"
DdlSerials.DataValueField = "SerialNo"
DdlSerials.DataSource = SqlDS.Tables(0)
DdlSerials.DataBind()
DdlSerials.Items.Insert(0, "Select Serial No")
plhSelect.Controls.Add(DdlSerials)
End If
End If
End If
Catch ex As Exception
lblText.Text = ex.ToString
Catch ex As SqlException
lblText.Text = ex.ToString
End Try
SqlConn.Close()
End If
End Sub
Private Sub DdlSerials_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs)
'This never fires
End Sub
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
' lblErrorMsg.Text = DdlSerials.SelectedItem.Text
'This gives an error and reloads the page
End Sub
End Class
-----------------------------------------------------------
I just moved over to VS.net and trying to design an application using ASP.net. I am having some trouble with the
DropDownList.
1. The event SelectedItemChanged doesnot fire.
2. I used a button and this also reloads the page. I am sure there are some tags I missed.
Any help is appriciated.
thanks
Sid
heres my code:
--------------------------------------------------------------
Imports System.Data.SqlClient
Public Class updateBuild
Inherits System.Web.UI.Page
' Dim DdlSerials As New System.Web.UI.WebControls.DropDownList
'Public Event ListChanged(ByVal sender As Object, ByVal e As EventArgs)
#Region " Web Form Designer Generated Code "
'This call is required by the Web Form Designer.
<System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
Me.SqlConn = New System.Data.SqlClient.SqlConnection
Me.SqlComm = New System.Data.SqlClient.SqlCommand
'
'SqlConn
'
Me.SqlConn.ConnectionString = "workstation id=ASPSERVER;packet size=4096;integrated security=SSPI;data source=AS" & _
"PSERVER;persist security info=False;initial catalog=PCTracker"
'
'SqlComm
'
Me.SqlComm.CommandText = "SELECT PCData.* FROM PCData WHERE (SerialNO = @SerialNo) OR (SONo = @SONo)"
Me.SqlComm.Connection = Me.SqlConn
Me.SqlComm.Parameters.Add(New System.Data.SqlClient.SqlParameter("@SerialNo", System.Data.SqlDbType.NVarChar, 50, "SerialNO"))
Me.SqlComm.Parameters.Add(New System.Data.SqlClient.SqlParameter("@SONo", System.Data.SqlDbType.NVarChar, 50, "SONo"))
End Sub
Protected WithEvents Table1 As System.Web.UI.HtmlControls.HtmlTable
Protected WithEvents tbxSerialNumber As System.Web.UI.WebControls.TextBox
Protected WithEvents tbxSalesOrderNo As System.Web.UI.WebControls.TextBox
Protected WithEvents Button1 As System.Web.UI.WebControls.Button
Protected WithEvents SqlConn As System.Data.SqlClient.SqlConnection
Protected WithEvents SqlComm As System.Data.SqlClient.SqlCommand
Protected WithEvents lblErrorMsg As System.Web.UI.WebControls.Label
Protected WithEvents plhSelect As System.Web.UI.WebControls.PlaceHolder
Protected WithEvents lblText As System.Web.UI.WebControls.Label
Protected WithEvents DgrRecord As System.Web.UI.WebControls.DataGrid
Protected WithEvents DdlSerials As System.Web.UI.WebControls.DropDownList
Protected WithEvents Button2 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
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
AddHandler DdlSerials.SelectedIndexChanged, AddressOf DdlSerials_SelectedIndexChanged
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim SqlDS As New DataSet
Dim SqlDV As New DataView
' Dim DdlSerials As New DropDownList
If tbxSerialNumber.Text = "" And tbxSalesOrderNo.Text = "" Then
lblErrorMsg.Text = " Enter Atleast one value"
Else
' Response.Write("IN ELSE")
Try
SqlConn.Open()
SqlComm.Parameters("@SerialNo").Value = CStr(tbxSerialNumber.Text)
SqlComm.Parameters("@SONo").Value = CStr(tbxSalesOrderNo.Text)
Dim SqlAdapter As New SqlDataAdapter
SqlAdapter.SelectCommand = SqlComm
SqlAdapter.Fill(SqlDS)
'SqlDV.RowFilter = "SerialNO = '" & CStr(tbxSalesOrderNo.Text) & "'"
'Response.Write(SqlDV.Count)
SqlConn.Close()
If SqlDS.Tables(0).Rows.Count = 0 Then
lblText.Text = "No Records found"
Else
If SqlDS.Tables(0).Rows.Count = 1 Then
lblText.Text = "1 match"
Else
If SqlDS.Tables(0).Rows.Count > 1 Then
lblText.Text = SqlDS.Tables(0).Rows.Count & " records found"
DdlSerials.Items.Clear()
DdlSerials.Visible = True
' DdlSerials.AutoPostBack = False
DdlSerials.DataTextField = "SerialNo"
DdlSerials.DataValueField = "SerialNo"
DdlSerials.DataSource = SqlDS.Tables(0)
DdlSerials.DataBind()
DdlSerials.Items.Insert(0, "Select Serial No")
plhSelect.Controls.Add(DdlSerials)
End If
End If
End If
Catch ex As Exception
lblText.Text = ex.ToString
Catch ex As SqlException
lblText.Text = ex.ToString
End Try
SqlConn.Close()
End If
End Sub
Private Sub DdlSerials_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs)
'This never fires
End Sub
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
' lblErrorMsg.Text = DdlSerials.SelectedItem.Text
'This gives an error and reloads the page
End Sub
End Class
-----------------------------------------------------------