?
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,144 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

On Demand Webinar: Networking for the Cloud Era

Did you know SD-WANs can improve network connectivity? Check out this webinar to learn how an SD-WAN simplified, one-click tool can help you migrate and manage data in the cloud.

Question has a verified solution.

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

Lots of people ask this question on how to extend the “MembershipProvider” to make use of custom authentication like using existing database or make use of some other way of authentication. Many blogs show you how to extend the membership provider c…
The article shows the basic steps of integrating an HTML theme template into an ASP.NET MVC project
Michael from AdRem Software explains how to view the most utilized and worst performing nodes in your network, by accessing the Top Charts view in NetCrunch network monitor (https://www.adremsoft.com/). Top Charts is a view in which you can set seve…
In this video, Percona Director of Solution Engineering Jon Tobin discusses the function and features of Percona Server for MongoDB. How Percona can help Percona can help you determine if Percona Server for MongoDB is the right solution for …
Suggested Courses

777 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