下面是模仿的DropDownList的效果
支持圖片
多列
換行等
WebDropDownListaspx <%@ Page language=
c#
Codebehind=
WebDropDownList
aspx
cs
validateRequest=
false
AutoEventWireup=
false
Inherits=
eMeng
WebDropDownList
%>
<HTML>
<HEAD>
<title>模擬下拉列表框</title>
<meta http
equiv=
Content
Type
content=
text/html; charset=gb
>
<style>BODY {
FONT:
px 宋體
}
TD {
FONT:
px 宋體
}
DIV {
FONT:
px 宋體
}
LABEL {
PADDING
RIGHT:
px; PADDING
LEFT:
px; PADDING
BOTTOM:
px; PADDING
TOP:
px; HEIGHT:
px
}
link_box {
CURSOR: default; TEXT
ALIGN: left
}
link_head {
BORDER
RIGHT:
px inset; BORDER
TOP:
px inset; BORDER
LEFT:
px inset; WIDTH:
%;
BORDER
BOTTOM:
px inset; HEIGHT:
px
}
link_text {
PADDING
LEFT:
px; BACKGROUND: #fff
}
link_arrow
{
BORDER
RIGHT:
px outset; BORDER
TOP:
px outset; BACKGROUND: buttonface;
FONT:
px marlett; BORDER
LEFT:
px outset; WIDTH:
px;
BORDER
BOTTOM:
px outset; HEIGHT:
%; TEXT
ALIGN: center
}
link_arrow
{
BORDER
RIGHT: buttonshadow
px solid; PADDING
RIGHT:
px;
BORDER
TOP: buttonshadow
px solid; PADDING
LEFT:
px;
BACKGROUND: buttonface; PADDING
BOTTOM:
px; FONT:
px marlett;
BORDER
LEFT: buttonshadow
px solid; WIDTH:
px; PADDING
TOP:
px;
BORDER
BOTTOM: buttonshadow
px solid; HEIGHT:
%; TEXT
ALIGN: center
}
link_value {
BORDER
RIGHT:
px solid; BORDER
TOP:
px solid; FILTER: alpha(opacity:
);
VISIBILITY: hidden; OVERFLOW
X: hidden; OVERFLOW: auto; BORDER
LEFT:
px solid;
BORDER
BOTTOM:
px solid; POSITION: absolute
}
link_record
{
BORDER
TOP: #eee
px solid; PADDING
LEFT:
px; BACKGROUND: #fff;
WIDTH:
%; COLOR: #
; HEIGHT:
px
}
link_record
{
BORDER
TOP: #
px solid; PADDING
LEFT:
px; BACKGROUND: #
;
WIDTH:
%; COLOR: #fe
; HEIGHT:
px
}
</style>
<script>
var dropShow=false
var currentID
function dropdown(el){
if(dropShow){
dropFadeOut()
}else{
currentID=el
el
style
visibility=
visible
dropFadeIn()
}
}
function dropFadeIn(){//選單淡入的效果
if(currentID
filters
alpha
opacity<
){
currentID
filters
alpha
opacity+=
fadeTimer=setTimeout(
dropFadeIn()
)
}else{
dropShow=true
clearTimeout(fadeTimer)
}
}
function dropFadeOut(){//選單淡出的效果
if(currentID
filters
alpha
opacity>
){
clearTimeout(fadeTimer)
currentID
filters
alpha
opacity
=
fadeTimer=setTimeout(
dropFadeOut()
)
}else{
dropShow=false
currentID
style
visibility=
hidden
}
}
function dropdownHide(){
if(dropShow){
dropFadeOut()
dropShow=false
}
}
function hiLight(el){//高亮度顯示指標位置
if(dropShow){
for(i=
;i<el
parentElement
childNodes
length;i++){
el
parentElement
childNodes(i)
className=
link_record
}
el
className=
link_record
}
}
function CheckMe(el){//替換顯示內容
document
all
text
innerText=el
innerText
}
document
onclick=dropdownHide
</script>
</HEAD>
<body text=
#
onload=
document
all
form
reset()
>
<div >模擬下拉框</div>
<form id=
form
onsubmit=
alert(city
value)
runat=
server
>
<table>
<tr>
<td>
<div class=
link_box
onselectstart=
return false
>
<div class=
link_head
onclick=
dropdown(value
)
>
<table height=
%
cellSpacing=
cellPadding=
width=
%
border=
>
<tr>
<td>
<div class=
link_text
><nobr><label id=
text
>請選擇?</label></nobr></div>
</td>
<td align=
right
width=
>
<div onmouseup=
this
className=
link_arrow
class=
link_arrow
onmousedown=
this
className=
link_arrow
onmouseout=
this
className=
link_arrow
>
</div>
</td>
</tr>
</table>
</div>
<div class=
link_value
id=
value
>
<asp:datagrid id=
DataGrid
runat=
server
AutoGenerateColumns=
False
Font
Size=
px
Width=
%
ShowHeader=
False
>
<Columns>
<asp:BoundColumn DataField=
Title
SortExpression=
Title
DataFormatString=
<img src=
/Images/meng
gif
align=
absmiddle
> {
}
>
</asp:BoundColumn>
<asp:BoundColumn DataField=
CreateDate
SortExpression=
CreateDate
HeaderText=
DataFormatString=
{
:yyyy年MM月dd日}
></asp:BoundColumn>
</Columns>
</asp:datagrid>
<div id=
mx
>
<div class=
link_record
onmouseover=
hiLight(this)
onclick=
CheckMe(this);document
all
form
city
value=this
innerText
><label>北京市</label></div>
<div class=
link_record
onmouseover=
hiLight(this)
onclick=
CheckMe(this);document
all
form
city
value=this
innerText
><label>上海市</label></div>
<div class=
link_record
onmouseover=
hiLight(this)
onclick=
CheckMe(this);document
all
form
city
value=this
innerText
><label>河南省</label></div>
<div class=
link_record
onmouseover=
hiLight(this)
onclick=
CheckMe(this);document
all
form
city
value=this
innerText
><label>深圳市</label></div>
<div class=
link_record
onmouseover=
hiLight(this)
onclick=
CheckMe(this);document
all
form
city
value=this
innerText
><label>大連市</label></div>
<div class=
link_record
onmouseover=
hiLight(this)
onclick=
CheckMe(this);document
all
form
city
value=this
innerText
><label>雲南省</label></div>
</div>
</div>
</div>
</td>
<td><input type=
hidden
value=
您尚未選擇
name=
city
> <input type=
submit
value=
確定
>
</td>
</tr>
</table>
</form>
</body>
</HTML>
WebDropDownListaspxcs using System;
using System
Collections;
using System
ComponentModel;
using System
Data;
using System
Drawing;
using System
Web;
using System
Web
SessionState;
using System
Web
UI;
using System
Web
UI
WebControls;
using System
Web
UI
HtmlControls;
using System
Data
OleDb;
namespace eMeng
{
/// <summary>
/// ShowList 的摘要說明
/// </summary>
public class WebDropDownList : System
Web
UI
Page
{
protected System
Web
UI
WebControls
DataGrid DataGrid
;
private void Page_Load(object sender
System
EventArgs e)
{
DataGrid
Columns[
]
ItemStyle
Width = Unit
Pixel(
);
DataGrid
Columns[
]
ItemStyle
Width = Unit
Pixel(
);
Data_Bind();
}
public void Data_Bind()
{
Response
CacheControl =
no
cache
;
Response
Expires =
;
try
{
string strSQL =
SELECT id
objectGuid
Title
CreateDate
HitCount FROM Document ORDER BY id DESC
;
string cnString = (new Connection())
Con
From:http://tw.wingwit.com/Article/program/Java/hx/201311/26949.html