Click to See Complete Forum and Search --> : ListBox not working on postback...
Lee Peart
October 2nd, 2002, 05:27 AM
Hi,
I have a listbox which is populated with data from my DB. The remaining information in the page depends on the selected listbox item.
When the user picks another item in the list I call OnSelectedItemChanged to refresh the information displayed on the page. Unfortunately the page fails to reload and gets stuck while redrawing the ListBox.
Does anyone know what I'm possibly doing wrong or can point me in the right direction for a working example of using this method?
Cheers
MRutledge
October 3rd, 2002, 04:40 AM
can you post the codebehind page so I can take a look at the code.
matt
Lee Peart
October 3rd, 2002, 06:44 AM
Thanks for the offer Matt. I hope you can let me know what I'm doing wrong, this is driving me nuts!!!
I don't use codebehind for this, but I can let you see an abbreviated version of the code I am using...
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=windows-1252">
<meta name="GENERATOR" content="Microsoft FrontPage 4.0">
<meta name="ProgId" content="FrontPage.Editor.Document">
<title>New Page 1</title>
</head>
<body>
<pre><font size="2"><%@ Page Explicit="True" Language="VB" Debug="True" %>
<%@ Import Namespace="System.Data" %>
<%@ Import Namespace="System.Data.OleDb" %>
<html>
<script runat="server">
Dim gUsNa as string
<font color="#0000FF">' Initial page loading works perfect every time
</font>Sub Page_Load(Sender As Object, E As EventArgs)
gUsNa = Request.Cookies("LadLogin2")("Name")
If Not IsPostBack Then
Dim Connect As OleDbConnection = New OleDbConnection
Dim Adapter As OleDbDataAdapter = New OleDbDataAdapter
Dim ClassyDS As DataSet = New DataSet
Dim ConnectString, SelectStatement As String
Dim NewWarID as String
Dim Row As DataRow
Dim I as Integer
NewWarID = Request.QueryString("MDetails")
SelectStatement = "Select * from MDetails Order By MName"
ConnectString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & Server.MapPath("\db\maps.mdb")
Connect.ConnectionString = ConnectString
Adapter.SelectCommand = new OleDbCommand(SelectStatement, Connect)
Adapter.SelectCommand.Connection.Open
Adapter.Fill(ClassyDS, "MDetails")
for I = 0 to (ClassyDS.Tables("MDetails").Rows.Count - 1)
lstMapChoice.Items.Add(ClassyDS.Tables("MDetails").Rows(I).Item("Mname"))
next
Adapter.SelectCommand.Connection.Close
ClassyDS.Clear()
Connect.Close()
lstmapchoice.items(0).selected = True
mappic.imageurl="images/" & lstMapChoice.Selecteditem.Text & ".jpg"
End If
End Sub
<font color="#0000FF">' Using postback to update the screen locks up!!!
</font><font color="#FF0000">Sub lstMapChoice_Change(Sender As Object, E As EventArgs)
mappic.imageurl="images/" & lstMapChoice.Selecteditem.Text & ".jpg"
End Sub
</font>
<font color="#0000FF">' Skipping some irrelevant code here...
</font>
</script>
<body text="#FFFFFF" bgcolor="#800000" leftmargin="30" topmargin="30">
<form runat="server">
<% %>
<font color="#0000FF">' Display listbox and chosen image...
</font><table border="0" cellspacing="1" style="border-collapse: collapse" width="600">
<tr>
<td width="150">Select Map:</td>
<td width="450" align="left" valign="top">&nbsp;</td>
</tr>
<tr>
<td width="150"><asp:listbox id="lstMapChoice"
Rows="13"
</font> <font size="2">runat="server"
</font> <font size="2"> Selectionmode="single"<font color="#FF0000">
</font> <font color="#FF0000">onselectedindexchanged="LstMapChoice_Change"</font>
autopostback="true"></asp:listbox><br></td>
<td width="450" align="left" valign="top"><asp:image id="mappic" RUNAT="server"></asp:image></td>
</tr>
</table>
<br>
<font color="#0000FF">' Skipping more irrelevant code here...
</font></form>
</body>
</html>
</font></pre>
</body>
</html>
MRutledge
October 3rd, 2002, 06:07 PM
try a couple of things here.... I know casing in VB doesnt matter but make sure the Case for your function calls is the same...on your selectedindexchanged you have Lst..and the function is lst...
then instead of setting the image url right off put a label on the page and set the text of the label to the selected index....if that works then put the imageurl back in...if it doesnt work populate your drop down with predifined fields...this will tell you if it is actually the database calls or the selected index changed function.
from what i see right off the bat it looks like it should work if the casing and everything is the same....
matt
codeguru.com
Copyright Internet.com Inc., All Rights Reserved.