Error Event 'lstS_SelectedValueChanged' cannot be found. when trying to get value from listbox contr

M

Moe Sizlak

Hi There,

I am trying to get the value from a listbox, I have a class in my code
behind page and I have created a sub to try to capture the selected value of
the listbox but it keeps giving me an error 'Event
lstS_SelectedValueChanged' cannot be found. What am I doing wrong?

Moe


!---page code

<%@Page language="vb" inherits="CommonFunctions" src="Default.vb" %>
<form runat="server">

<script language="vb" runat="server">
Sub Page_Load(byVal obj As Object, byVal e As EventArgs)
If Not Page.IsPostBack Then
lstS.DataSource = CommonFunctions.BindStates
lstS.DataBind()
lstS.Items.Insert(0, new ListItem("By State","0"))
End If
End Sub
</script>

<asp:listbox id="lstS" runat="server" Rows="1" AutoPostBack="true"
DataTextField="Location" DataValueField="LocationID"
SelectedValueChanged="lstS_SelectedValueChanged"/>

<asp:TextBox id="txt1" width="40" maxlength= "40"
runat="server" />
</form>


!--- code behind page code

imports system
imports system.web
imports System.Configuration
imports system.web.ui
imports system.web.ui.webcontrols
imports system.web.ui.htmlcontrols
imports system.data
imports system.data.sqlclient
imports system.data.sqlclient.sqldatareader



Public Class CommonFunctions
Inherits System.web.ui.page
'Inherits System.Web.UI.UserControl
Protected WithEvents lstS As ListBox

public txt1 as Textbox


Public Shared Function BindStates() as SqlDataReader

Dim myConnection as New
SqlConnection(ConfigurationSettings.AppSettings("connectionString"))
Const strSQL as String = "SELECT LocationID, Location AS
Location " & _
"FROM tbLocation ORDER BY
Location"
Dim myCommand as New SqlCommand(strSQL, myConnection)
myConnection.Open()
Dim objDR as SqlDataReader
objDR = myCommand.ExecuteReader(CommandBehavior.CloseConnection)
Return objDr
End Function

Public Sub lstS_SelectedValueChanged(ByVal sender As System.Object,
ByVal e As System.EventArgs) Handles lstS.SelectedValueChanged
If lstS.SelectedIndex <> -1 Then
txt1.Text = lstS.SelectedValue
End If
End Sub


End Class
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,969
Messages
2,570,161
Members
46,708
Latest member
SherleneF1

Latest Threads

Top