Solved

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

Posted on 2006-06-25
2
1,143 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 200 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

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

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…
ASP.Net to Oracle Connectivity Recently I had to develop an ASP.NET application connecting to an Oracle database.As I am doing it first time ,I had to solve several problems. This article will help to such developers  to develop an ASP.NET client…
Michael from AdRem Software outlines event notifications and Automatic Corrective Actions in network monitoring. Automatic Corrective Actions are scripts, which can automatically run upon discovery of a certain undesirable condition in your network.…
Do you want to know how to make a graph with Microsoft Access? First, create a query with the data for the chart. Then make a blank form and add a chart control. This video also shows how to change what data is displayed on the graph as well as form…

729 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