ASP.NET Listbox Populated With SQL, Then check Values

D

Dessip

Hey there,

my question is, I have got 2 List Boxes, on a page, and listbox 1
generates list box 2 items, but both are generated from SQL, but its
not worknig on auto post back:

Code
================================================
Private Sub LsbImporting_SelectedIndexChanged(ByVal sender As
System.Object, ByVal e As System.EventArgs) Handles
ListBox2.SelectedIndexChanged
Dim x
For x = 0 To ListBox2.Items.Count - 1
If ListBox2.Items(x).Selected Then Label1.Text += "1"
Next
End Sub
=================================================


That is getting called all the time, but the selected value always =
False, even if i have selected some items

here is the HTML for the list box:
================================================
div>
<asp:listbox id="lsbImporting" CssClass="lblMain"
Runat="server" AutoPostBack="True">Importing From:</asp:listbox>
<asp:listbox id="lsbImportRegion" CssClass="lsbMain"
Runat="server" SelectionMode="Multiple"></asp:listbox>
</div>
================================================

Here is the SQL im useing to import the data:
================================================
Public Function ReturnSQLDataReader(ByVal SQLConnString As String,
ByVal sSQLCmd As String) As SqlClient.SqlDataReader
Dim oSQLConn As SqlConnection = New SqlConnection
oSQLConn.ConnectionString = SQLConnString
oSQLConn.Open()
Dim SQLCmd As SqlClient.SqlCommand = New
SqlClient.SqlCommand(sSQLCmd, oSQLConn)
'Dim SQLReader As SqlClient.SqlDataReader
Return SQLCmd.ExecuteReader(CommandBehavior.CloseConnection)
'SQLReader = Nothing
oSQLConn.Close()
oSQLConn = Nothing
End Function

-----------------------------------------------------------

Dim SQLFun As New SQLFunctions
lsbImporting.DataSource = SQLFun.ReturnSQLDataReader("Data
Source=127.0.0.1\SQLEXPRESS;Initial Catalog=ProduceTracker;Integrated
Security=SSPI;Packet Size=4096;", "SELECT DISTINCT year FROM
CropImportExport ORDER BY Year DESC")
lsbYear.DataTextField = "Year"
lsbYear.DataBind()
================================================

Any help would be excelent, i have no idea why they are not showing i
was guessing it was because of the SQL, but im not sure.

Thanks in advance

Chris
 
D

Dessip

I ahve fixed it the problem i was having is i fifnt have
If Not IsPostBack = True Then
 

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,968
Messages
2,570,153
Members
46,701
Latest member
XavierQ83

Latest Threads

Top