<%@ Import Namespace="System.Data" %>
<%@ Import Namespace="System.Data.SqlClient" %>
<head>
<script language="vb" runat="server">
public Sname as string '来源数据表
public TextField as string '显示在DropDownlist的列名称
public ValueField as string '选取后返回值的列名称
public CompareValue as string '结合后比较的值
public CompareField as string '结合后比较的列
public SessionName as string '目前连接的Session名称
	public sub Show()
		Dim dt as DropDownList=NP
		Dim NowDs as DataSet = new DataSet()
		Dim Source as SqlConnection = Ctype(Session(SessionName),SqlConnection)
		Dim NComm1 as SqlDataAdapter = new SqlDataAdapter(Sname,Source)
		NComm1.Fill(NowDS, "NowDrop")'取得来源
		NP.DataSource=NowDS.Tables("NowDrop").DefaultView
		NP.DataTextField=TextField
		NP.DataValueField=ValueField
		NP.DataBind()
		if CompareValue="" then'若未传入比对值
			NP.SelectedIndex=0 '选取第一个选项
			exit sub
		end if
		dim f as integer =0 
		Dim Row as DataRow
		for each Row in NowDS.Tables("NowDrop").Rows
			if Row(CompareField).ToString()=CompareValue then
				dt.SelectedIndex=f '找到及设定选取索引值
				exit for
			end if
			f+=1
		next
	end sub
	public ReadOnly Property GetNowSelect() as string
		get
			return NP.SelectedItem.Value
		end get
	end property
</script>
</head>
<asp:DropDownlist ID="NP" Runat="server" />