由于listbox中显示的实际内容比listbox框中大,所以一部分信息无法显示,想做一个横向的滚动条,不知道怎么才能实现。我的问题是asp.net中listbox的横向滚动条是如何实现的,对这方面有解决办法的朋友请赐教。。在此谢过先。

解决方案 »

  1.   

    感兴趣,也去网上找了相关资料,winform下可以,webform下没找到,同关注
      

  2.   

    http://blog.csdn.net/rickjelly2004/archive/2005/04/06/338124.aspx
      

  3.   

    rickjelly2004(rick & jelly) ( ) 信誉:99 的代码,是一个自己开发的web控件,我试了下,可以编译,但是我在webform里面用的时候有点问题。Imports System.ComponentModel
    Imports System.Web.UI
    Imports System.Web.UI.WebControls
    Imports System.Web
    Imports System.Drawing.Design
    Imports System.Text.RegularExpressions<DefaultProperty("Text"), ToolboxData("<{0}:XScrollListBox runat=server></{0}:XScrollListBox>")> _
    Public Class XScrollListBox
        Inherits System.Web.UI.WebControls.WebControl    Private WithEvents conFromListBox As ListBox    Public Enum ScrollBar
            none
            All
            X
            Y
        End Enum#Region "プロパティ"
    #Region "親クラスから継承された表示プロパティ"    'コントロールのID用
        Public Overrides Property ID() As String
            Get
                Dim mID As String
                mID = IIf(viewstate("mID") Is Nothing, MyBase.ID, viewstate("mID"))
                conFromListBox.ID = mID & "_SubFromListBox"
                Return mID
            End Get
            Set(ByVal Value As String)
                viewstate("mID") = Value
            End Set
        End Property    'CssClass
        <NotifyParentProperty(True)> _
            Public Overrides Property CssClass() As String
            Get
                Return MyBase.CssClass
            End Get
            Set(ByVal Value As String)
                MyBase.CssClass = Value            If Not conFromListBox Is Nothing Then
                    conFromListBox.CssClass = MyBase.CssClass
                End If
            End Set
        End Property    'BackColor
        <NotifyParentProperty(True)> _
            Public Overrides Property BackColor() As System.Drawing.Color
            Get
                Return MyBase.BackColor
            End Get
            Set(ByVal Value As System.Drawing.Color)
                MyBase.BackColor = Value
                If Not conFromListBox Is Nothing Then
                    conFromListBox.BackColor = MyBase.BackColor
                End If
            End Set
        End Property    'ForeColor
        <NotifyParentProperty(True)> _
            Public Overrides Property ForeColor() As System.Drawing.Color
            Get
                Return MyBase.ForeColor
            End Get
            Set(ByVal Value As System.Drawing.Color)
                MyBase.ForeColor = Value
                If Not conFromListBox Is Nothing Then
                    conFromListBox.ForeColor = MyBase.ForeColor
                End If
            End Set
        End Property    'Controlsプロパティ
        Public Overrides ReadOnly Property Controls() As System.Web.UI.ControlCollection
            Get
                EnsureChildControls()
                Return MyBase.Controls
            End Get
        End Property
    #End Region    <NotifyParentProperty(True), _
           Category("ChildControl"), Description("listbox")> _
           Public ReadOnly Property SubFromListBox() As ListBox
            Get
                Me.EnsureChildControls()
                Return conFromListBox
            End Get
        End Property    <NotifyParentProperty(True), _
              Category("ChildControl"), Description("scrollType")> _
              Public Property ScrollType() As ScrollBar
            Get
                Me.EnsureChildControls()
                Return viewstate("scroll")
            End Get
            Set(ByVal Value As ScrollBar)
                viewstate("scroll") = Value
            End Set
        End Property    <Category("Behavior"), DefaultValue("150px"), _
        Description("scrollWidth")> _
        Public Property ScrollBarWidth() As Unit
            Get
                Return IIf(viewstate("mScrollBarWidth") Is Nothing, "", viewstate("mScrollBarWidth"))
            End Get
            Set(ByVal Value As Unit)
                viewstate("mScrollBarWidth") = Value
                If Not Me.conFromListBox Is Nothing Then
                    Me.conFromListBox.Width = Value
                End If        End Set
        End Property    <Category("Behavior"), DefaultValue("150px"), _
        Description("scrollHeight")> _
        Public Property ScrollBarHeight() As Unit
            Get
                Return IIf(viewstate("mScrollBarHeight") Is Nothing, "", viewstate("mScrollBarHeight"))
            End Get
            Set(ByVal Value As Unit)
                viewstate("mScrollBarHeight") = Value
                If Not Me.conFromListBox Is Nothing Then
                    Me.conFromListBox.Height = Value
                End If        End Set
        End Property
    #End Region    Public Sub New()
            Me.ScrollBarWidth = Unit.Pixel(150)
            Me.ScrollBarHeight = Unit.Pixel(150)
        End Sub    Private Function IsDesignMode() As Boolean
            If (HttpContext.Current Is Nothing) Then
                Return True
            Else
                Return False
            End If
        End Function    Protected Overrides Sub CreateChildControls()
            If conFromListBox Is Nothing Then
                conFromListBox = New ListBox
                conFromListBox.Height = Unit.Pixel(150)
                conFromListBox.Width = Unit.Pixel(150)
            End If
            Call SetChildLayout()
        End Sub    Private Sub SetChildLayout()
            Dim htmlTable As Table
            Dim htmlTableRow As TableRow
            Dim divPanel As Panel        htmlTable = New Table        htmlTable.BorderWidth = Unit.Pixel(0)
            htmlTable.CellSpacing = 0
            htmlTable.CellPadding = 0        htmlTableRow = New TableRow
            htmlTableRow.Cells.Add(New TableCell)
            htmlTableRow.Cells(0).ColumnSpan = 4
            htmlTableRow.Cells(0).HorizontalAlign = HorizontalAlign.Left        divPanel = New Panel
            divPanel.ID = Me.ID & "_TopDiv"        Select Case Me.ScrollType
                Case ScrollBar.All
                    divPanel.Style.Add("overflow", "Scroll")
                Case ScrollBar.X
                    divPanel.Style.Add("overflow-x", "Scroll")
                Case ScrollBar.Y
                    divPanel.Style.Add("overflow-y", "Scroll")
            End Select        divPanel.Width = Me.ScrollBarWidth
            divPanel.Height = Me.ScrollBarHeight
            Me.conFromListBox.Width = Me.ScrollBarWidth
            Me.conFromListBox.Height = Me.ScrollBarHeight
            divPanel.Controls.Add(conFromListBox)
            htmlTableRow.Cells(0).Controls.Add(divPanel)        htmlTable.Rows.Add(htmlTableRow)
            MyBase.Controls.Add(htmlTable)
        End Sub    Protected Overrides Sub Render(ByVal writer As System.Web.UI.HtmlTextWriter)
            Me.EnsureChildControls()        If IsDesignMode() Then
                MyBase.Controls.Clear()
                Call SetChildLayout()
            End If        MyBase.Render(writer)
        End Sub    Protected Overrides Sub AddParsedSubObject(ByVal obj As Object)
            If TypeOf (obj) Is ListBox Then
                Me.conFromListBox = obj
            End If
        End Sub    Private Sub conFromListBox_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles conFromListBox.SelectedIndexChanged
            RaiseBubbleEvent(sender, e)
        End Sub
    End Class
      

  4.   

    楼上的,你是指把listbox放到div中,然后设置div的style来滚动?
      

  5.   

    <div style="OVERFLOW: auto; WIDTH: 100px; HEIGHT: 102px">
    <asp:ListBox id="ListBox1" runat="server" Rows="5">
    <asp:ListItem Value="111111111111111111111111111111111111">111111111111111111111111111111111111</asp:ListItem>
    <asp:ListItem Value="2222222222222222222222222222222222">2222222222222222222222222222222222</asp:ListItem>
    <asp:ListItem Value="333333333333333333333333">333333333333333333333333</asp:ListItem>
    <asp:ListItem Value="44444444444444444444444444444">44444444444444444444444444444</asp:ListItem>
    <asp:ListItem Value="55555555555555555555555555">55555555555555555555555555</asp:ListItem>
    <asp:ListItem Value="666666666666666666666666666">666666666666666666666666666</asp:ListItem>
    <asp:ListItem></asp:ListItem>
    </asp:ListBox>
    </div>