Results 1 to 2 of 2

Thread: listbox.selecteditem.text

  1. #1

    Thread Starter
    Hyperactive Member Sneeden's Avatar
    Join Date
    Oct 2001
    Location
    Sneedville
    Posts
    258

    listbox.selecteditem.text

    I have a listbox on an asp page. When the user clicks on a selection I want to pass the text back in a querystring. Why is it that no matter what item the user clicks on, it does not affect listbox.selecteditem.text? IE...if the index is 1 when the page is loaded and the user clicks on the 3rd index, the code says that the selected index is 1?

    Here is the code I am using:
    VB Code:
    1. Private Sub lstSubDirs_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles lstSubDirs.SelectedIndexChanged
    2.     Response.Redirect("WebPage1.aspx?dir=" & lstSubDirs.SelectedItem.Text)
    3. End Sub

    I have autopostback=true (else this event won't fire). I am not sure if that matters.

  2. #2
    Lively Member
    Join Date
    Jul 2002
    Location
    Gateshead, UK
    Posts
    101

    Try javascript...

    I think that's too much of a mouthful in VB - javascript would probably be quite a bit shorter, whilst still doing what you want it to do...

    If you just want a clientside script to parse the select.options[select.selectedIndex].text (Javascript), and then put it as a Querystring, you could use something like this:

    <script language="javascript"><!--
    function parseGET(theSelect) {
    var sText=theSelect.options[theSelect.selectedIndex].text;

    // HTTP form parsing goes here, for spaces-to-"+", UTF8 character codes, etc. (from sText string)

    window.location="the_url?"+sText; // redirect to a page URL, with the JS parsed Querystring appended. This could be modified to use like an invisible image, for instance - or an IFRAME, etc; to eliminate the main page refreshing/loading. }
    --></script>

    <!-- other page stuff -->

    <!-- then, the <select> input - or whatever -->

    <select name="egSelect">
    <option>Option 1
    <option>Option 2
    <option>Option 3
    </select><br>

    <!-- an optional button, to call parseGET(); if left out just use an onChange/Click event handler, or something... -->

    <input type="button" value="Select it!" onclick="if(egSelect.selectedIndex!=-1) {parseGET(egSelect);}else{alert('Please select an option from the list');}">


    P.S: As an even easier way, just use a conventional HTML form, of course, using the "GET" method - although this is probably not what you want...

    P.P.S: There I go again, rattling on about a clientside solution - that isn't even in VB/S - and it probably isn't what you're looking for... Ah well - I try, I try...
    <% Session("OwNeD")=True %><html><body>Blah... <%="Now get your ass back to the twilight zone..."%></body></html>

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