Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Is there a readonly equiv. for a listbox in ASP.NET 2005 using VB.NET?

Posted on 2006-06-25
2
Medium Priority
?
1,145 Views
Last Modified: 2008-02-20
Is there an equiv. for the readonly property of a textbox control in a listbox control in ASP.NET?  If I set the enabled property to false on a listbox control, the user can't change the selections (which is good), but also can't scroll up and down (which is the problem).  I need the user to be able to scroll up and down but not be able to change the selections.  Any ideas?
0
Comment
Question by:stev0931
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 

Accepted Solution

by:
kskim43 earned 600 total points
ID: 16981324
I don't think there is a property you can just set on the listbox object to do this.
I had a similar situation and had to use javascript on the client to reselect the original value in the listbox when a user changed the selected item.
I could have autoposted back and maybe just rebound the listbox with the onSelectedIndexChanged event, but seemed like a wasted trip back to the server.

I only had one selected item, but I think you can set the selected property of each list item when you generate the javascript code in the load event.

Also, you may want to check out this article from Code Project. Didn't have time to play with it yet, but looks promising..
http://www.codeproject.com/combobox/readonlycombo.asp


Here's the code..

<HTML>
      <body MS_POSITIONING="GridLayout">
            <form id="Form1" method="post" runat="server">
                  <asp:ListBox ID=lst Runat=server Width=100 onChange="StopChange(this);"  />
            </form>
      </body>
</HTML>


Code behind:


    Protected WithEvents lst As System.Web.UI.WebControls.ListBox

    Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        'Put user code to initialize the page here
        If Not Page.IsPostBack Then
            LoadPage()
        End If
    End Sub

    Private Sub LoadPage()
        Dim selectedIndx As Integer

        selectedIndx = 3

        lst.Items.Add("A1")
        lst.Items.Add("b1")
        lst.Items.Add("c1")
        lst.Items.Add("d1")
        lst.Items.Add("e1")
        lst.Items.Add("f1")
        lst.Items.Add("g1")
       
        lst.Items(selectedIndx).Selected = True

        Dim script As String

        script = "<script language=javascript>"
        script &= "      function StopChange(obj) {"
        script &= "            obj.selectedIndex = " & selectedIndx & ";"
        script &= "      }"
        script &= "</script>"

        RegisterClientScriptBlock("stopChange", script)
    End Sub
0
 

Author Comment

by:stev0931
ID: 16981522
Thanks!
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In this Article, I will provide a few tips in problem and solution manner. Opening an ASPX page in Visual studio 2003 is very slow. To make it fast, please do follow below steps:   Open the Solution/Project. Right click the ASPX file to b…
In an ASP.NET application, I faced some technical problems. In this article, I list them out and show the solutions that I found.  I hope it will be useful. Problem: After closing a pop-up window, the parent page should be refreshed automaticall…
How to fix incompatible JVM issue while installing Eclipse While installing Eclipse in windows, got one error like above and unable to proceed with the installation. This video describes how to successfully install Eclipse. How to solve incompa…
Want to learn how to record your desktop screen without having to use an outside camera. Click on this video and learn how to use the cool google extension called "Screencastify"! Step 1: Open a new google tab Step 2: Go to the left hand upper corn…

604 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question