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

王朝asp·作者佚名  2006-01-09
窄屏简体版  字體: |||超大  

可选择值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 (dpliu@cbdsystem.com.cn)

''' *

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

 
 
 
免责声明:本文为网络用户发布,其观点仅代表作者个人观点,与本站无关,本站仅提供信息存储服务。文中陈述内容未经本站证实,其真实性、完整性、及时性本站不作任何保证或承诺,请读者仅作参考,并请自行核实相关内容。
 
 
© 2005- 王朝網路 版權所有 導航