Asp.net可输入下拉框服务器控件

类别:网站制作 点击:0 评论:0 推荐:
可选择值1 可选择值2 可选择值3

Imports System.ComponentModel
Imports System.Web.UI
Imports System.Web.UI.Design
Imports System.Web.UI.WebControls

'''/*
''' * CBDAspNet - ASP.Net Development Framework
''' * Copyright (C) 2004-2005 Chengdu Binary Digital Tech. Co.,Ltd.
''' *
''' * Company Homepage
''' *    http://www.cbdsystem.com.cn
''' *
''' * File Name: D:\CuteProject\CBDAspNet\CBDWebControls\CBDTextBox\CBDTextBox.vb
''' *
''' * Version:  1.0
''' * Modified: 2005年1月27日 10:00:46
''' *
''' * File Authors:
''' *      Ryan Liu ([email protected])
''' *

Namespace CBDAspNet.WebControls.HTML

    ''' <summary>
    ''' 可输入的下拉框控件
    ''' </summary>
    <ToolboxData("<{0}:TextBox runat=""server"" />")> _
    Public Class TextBox
        Inherits System.Web.UI.WebControls.TextBox

        Private _values As Hashtable

        Public _DropDownList As DropDownList

        Public Sub New()
            _DropDownList = New DropDownList
            _values = New Hashtable
        End Sub

        Public Property Values() As Hashtable
            Get
                Return _values
            End Get
            Set(ByVal Value As Hashtable)
                _values = Value
            End Set
        End Property

        Protected Overrides Sub Render(ByVal Output As System.Web.UI.HtmlTextWriter)

            Dim iWidth As Integer = MyBase.Width.Value
            If iWidth = 0 Then
                iWidth = 102
                'MyBase.Width = Unit.Parse("102px")
            End If

            Dim sWidth As Integer = iWidth + 16
            Dim spanWidth As Integer = sWidth - 18

            Output.Write("<div style=""POSITION:relative"">")
            Output.Write("<span style=""MARGIN-LEFT:" & spanWidth & "px;OVERFLOW:hidden;WIDTH:18px"">")

            _DropDownList.Width = Unit.Parse(sWidth & "px")
            _DropDownList.Style.Add("MARGIN-LEFT", "-" & spanWidth & "px")
            _DropDownList.Attributes.Add("onchange", "this.parentNode.nextSibling.value=this.value")

            If _values.Count > 0 Then
                For Each key As String In _values.Keys
                    Dim item As ListItem = New ListItem
                    item.Value = key
                    item.Text = _values(key)
                    _DropDownList.Items.Add(item)
                Next
            End If
            ''如果只有一个可选内容
            If _DropDownList.Items.Count = 1 Then
                Dim item As ListItem = New ListItem
                item.Value = ""
                item.Text = " "
                _DropDownList.Items.Add(item)
                _DropDownList.SelectedIndex = 1
            End If
            _DropDownList.RenderControl(Output)

            Output.Write("</span>")

            MyBase.Style.Clear()
            MyBase.Width = Unit.Parse(iWidth & "px")
            MyBase.Style.Add("left", "0px")
            MyBase.Style.Add("POSITION", "absolute")

            MyBase.Render(Output)

            Output.Write("</div>")

        End Sub

    End Class

End Namespace

本文地址:http://com.8s8s.com/it/it30829.htm