CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 4 of 4
  1. #1
    Join Date
    Apr 2001
    Posts
    514

    Unhappy ListBox not working on postback...

    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

  2. #2
    Join Date
    Oct 1999
    Location
    Colorado
    Posts
    288
    can you post the codebehind page so I can take a look at the code.

    matt

  3. #3
    Join Date
    Apr 2001
    Posts
    514
    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">&lt;%@ Page Explicit="True" Language="VB" Debug="True" %>
    &lt;%@ Import Namespace="System.Data" %>
    &lt;%@ Import Namespace="System.Data.OleDb" %>

    &lt;html>


    &lt;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(&quot;LadLogin2&quot;)(&quot;Name&quot;)
    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(&quot;MDetails&quot;)
    SelectStatement = "Select * from MDetails Order By MName"
    ConnectString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" &amp; Server.MapPath("\db\maps.mdb")
    Connect.ConnectionString = ConnectString
    Adapter.SelectCommand = new OleDbCommand(SelectStatement, Connect)
    Adapter.SelectCommand.Connection.Open
    Adapter.Fill(ClassyDS, &quot;MDetails&quot;)
    for I = 0 to (ClassyDS.Tables("MDetails").Rows.Count - 1)
    lstMapChoice.Items.Add(ClassyDS.Tables(&quot;MDetails&quot;).Rows(I).Item(&quot;Mname&quot;))
    next
    Adapter.SelectCommand.Connection.Close
    ClassyDS.Clear()
    Connect.Close()
    lstmapchoice.items(0).selected = True
    mappic.imageurl=&quot;images/&quot; &amp; lstMapChoice.Selecteditem.Text &amp; ".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=&quot;images/&quot; &amp; lstMapChoice.Selecteditem.Text &amp; ".jpg"
    End Sub
    </font>
    <font color="#0000FF">' Skipping some irrelevant code here...
    </font>
    &lt;/script>
    &lt;body text="#FFFFFF" bgcolor="#800000" leftmargin="30" topmargin="30">

    &lt;form runat="server">
    &lt;% %>
    <font color="#0000FF">' Display listbox and chosen image...
    </font>&lt;table border="0" cellspacing="1" style="border-collapse: collapse" width="600">
    &lt;tr&gt;
    &lt;td width="150">Select Map:&lt;/td>
    &lt;td width="450" align="left" valign="top">&amp;nbsp;&lt;/td>
    &lt;/tr&gt;
    &lt;tr&gt;
    &lt;td width="150">&lt;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=&quot;LstMapChoice_Change&quot;</font>
    autopostback="true">&lt;/asp:listbox>&lt;br>&lt;/td>
    &lt;td width="450" align="left" valign="top">&lt;asp:image id="mappic" RUNAT="server">&lt;/asp:image>&lt;/td>
    &lt;/tr&gt;
    &lt;/table>
    &lt;br>

    <font color="#0000FF">' Skipping more irrelevant code here...
    </font>&lt;/form>
    &lt;/body>

    &lt;/html>
    </font></pre>

    </body>

    </html>

  4. #4
    Join Date
    Oct 1999
    Location
    Colorado
    Posts
    288
    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

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured