Yeah it is. It's scoped outside of that function. Here's
the whole kit & kaboodle:
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()
End Sub
Protected WithEvents ListBox1 As
System.Web.UI.WebControls.ListBox
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
Protected nValue As Integer
Protected sValue As String
Private Sub Page_Load(ByVal sender As System.Object,
ByVal e As System.EventArgs) Handles MyBase.Load
Dim cnVortex As New SqlClient.SqlConnection
(System.Configuration.ConfigurationSettings.AppSettings
("ConnectionString"))
Dim cdAnimalTypes As New SqlClient.SqlCommand
("usp_GetAnimalTypes", cnVortex)
'cdAnimalTypes.CommandType =
CommandType.StoredProcedure
cnVortex.Open()
Dim daAnimalTypes As New SqlClient.SqlDataAdapter
(cdAnimalTypes)
Dim dsAnimalTypes As New DataSet
daAnimalTypes.Fill(dsAnimalTypes, "AnimalTypes")
ListBox1.DataSource = dsAnimalTypes
ListBox1.DataTextField = "ANIMAL_TYPE"
ListBox1.DataValueField = "ANIMAL_TYPE_ID"
ListBox1.DataBind()
' ListBox1.Items.Add("Test1")
' ListBox1.Items.Add("Test2")
End Sub
Private Sub Button1_Click(ByVal sender As
System.Object, ByVal e As System.EventArgs) Handles
Button1.Click
Try
Response.Write(Session("AnimalTypeID"))
sValue = ListBox1.Items
(ListBox1.SelectedIndex).Value
Response.Write(sValue)
Catch ex As Exception
Response.Write(ex.Message)
End Try
'Server.Transfer("EditAnimalTypes.aspx")
End Sub
Private Sub ListBox1_SelectedIndexChanged(ByVal sender
As System.Object, ByVal e As System.EventArgs) Handles
ListBox1.SelectedIndexChanged
End Sub
End Class