服务热线:13616026886

技术文档 欢迎使用技术文档,我们为你提供从新手到专业开发者的所有资源,你也可以通过它日益精进

位置:首页 > 技术文档 > JAVA > 新手入门 > 基础入门 > 查看文档

带图片的,多列的dropdownlist的实现


  下面是模仿的dropdownlist的效果,支持图片,多列,换行等。
  
  webdropdownlist.aspx
  
  <%@ 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=gb2312">
  <style>body {
  font: 12px 宋体
  }
  td {
  font: 12px 宋体
  }
  div {
  font: 12px 宋体
  }
  label {
  padding-right: 0px; padding-left: 4px; padding-bottom: 0px; padding-top: 3px; height: 19px
  }
  .link_box {
  cursor: default; text-align: left
  }
  .link_head {
  border-right: 2px inset; border-top: 2px inset; border-left: 2px inset; width: 100%;
  border-bottom: 2px inset; height: 23px
  }
  .link_text {
  padding-left: 2px; background: #fff
  }
  .link_arrow0 {
  border-right: 2px outset; border-top: 2px outset; background: buttonface;
  font: 14px marlett; border-left: 2px outset; width: 22px;
   border-bottom: 2px outset; height: 100%; text-align: center
  }
  .link_arrow1 {
  border-right: buttonshadow 1px solid; padding-right: 0px;
  border-top: buttonshadow 1px solid; padding-left: 2px;
  background: buttonface; padding-bottom: 0px; font: 14px marlett;
  border-left: buttonshadow 1px solid; width: 22px; padding-top: 2px;
  border-bottom: buttonshadow 1px solid; height: 100%; text-align: center
  }
  .link_value {
  border-right: 1px solid; border-top: 1px solid; filter: alpha(opacity:0);
  visibility: hidden; overflow-x: hidden; overflow: auto; border-left: 1px solid;
  border-bottom: 1px solid; position: absolute
  }
  .link_record0 {
  border-top: #eee 1px solid; padding-left: 2px; background: #fff;
  width: 100%; color: #000; height: 20px
  }
  .link_record1 {
  border-top: #047 1px solid; padding-left: 2px; background: #058;
  width: 100%; color: #fe0; height: 20px
  }
  </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<100){
  currentid.filters.alpha.opacity+=20
  fadetimer=settimeout("dropfadein()",50)
  }else{
  dropshow=true
  cleartimeout(fadetimer)
  }
  }
  function dropfadeout(){//选单淡出的效果
  if(currentid.filters.alpha.opacity>0){
  cleartimeout(fadetimer)
  currentid.filters.alpha.opacity-=20
  fadetimer=settimeout("dropfadeout()",50)
  }else{
  dropshow=false
  currentid.style.visibility="hidden"
  }
  }
  function dropdownhide(){
  if(dropshow){
  dropfadeout()
  dropshow=false
  }
  }
  function hilight(el){//高亮度显示指标位置
  if(dropshow){
  for(i=0;i<el.parentelement.childnodes.length;i++){
  el.parentelement.childnodes(i).classname="link_record0"
  }
  el.classname="link_record1"
  }
  }
  function checkme(el){//替换显示内容
  document.all.text1.innertext=el.innertext
  }
  document.onclick=dropdownhide
  </script>
  </head>
  <body text="#000000" onload="document.all.form1.reset()">
  <div style="padding:10px;border-bottom:2px solid red">模拟下拉框</div>
  <form id="form1" onsubmit="alert(city.value)" runat="server">
  <table>
  <tr>
  <td>
  <div class="link_box" onselectstart="return false" style="width: 100px">
  <div class="link_head" onclick="dropdown(value1)">
  <table height="100%" cellspacing="0" cellpadding="0" width="100%" border="0">
  <tr>
   <td>
   <div class="link_text"><nobr><label id="text1">请选择?</label></nobr></div>
   </td>
   <td align="right" width="22">
   <div onmouseup="this.classname='link_arrow0'" class="link_arrow0"
   onmousedown="this.classname='link_arrow1'" onmouseout="this.classname='link_arrow0'">6</div>
   </td>
  </tr>
  </table>
  </div>
  <div class="link_value" id="value1" style="width: 500px; height: 300px">
  <asp:datagrid id="datagrid1" runat="server" autogeneratecolumns="false" font-size="12px" width="100%"
  showheader="false">
  <columns>
  <asp:boundcolumn datafield="title" sortexpression="title"
   dataformatstring="<img src='http://dotnet.aspx.cc/images/meng.gif' align='absmiddle'> {0}">
   </asp:boundcolumn>
  <asp:boundcolumn datafield="createdate" sortexpression="createdate"
   headertext="" dataformatstring="{0:yyyy年mm月dd日}"></asp:boundcolumn>
  </columns>
  </asp:datagrid>
  <div id="mx">
  <div class="link_record0" onmouseover="hilight(this)"
   onclick="checkme(this);document.all.form1.city.value=this.innertext"><label>北京市</label></div>
  <div class="link_record0" onmouseover="hilight(this)"
   onclick="checkme(this);document.all.form1.city.value=this.innertext"><label>上海市</label></div>
  <div class="link_record0" onmouseover="hilight(this)"
   onclick="checkme(this);document.all.form1.city.value=this.innertext"><label>河南省</label></div>
  <div class="link_record0" onmouseover="hilight(this)"
   onclick="checkme(this);document.all.form1.city.value=this.innertext"><label>深圳市</label></div>
  <div class="link_record0" onmouseover="hilight(this)"
   onclick="checkme(this);document.all.form1.city.value=this.innertext"><label>大连市</label></div>
  <div class="link_record0" onmouseover="hilight(this)"
   onclick="checkme(this);document.all.form1.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>
  
  webdropdownlist.aspx.cs
  
  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 datagrid1;
  
  private void page_load(object sender, system.eventargs e)
  {
  datagrid1.columns[0].itemstyle.width = unit.pixel(400);
  datagrid1.columns[1].itemstyle.width = unit.pixel(100);
  data_bind();
  }
  
  public void data_bind()
  {
  response.cachecontrol = "no-cache";
  response.expires = -1;
  try
  {
  string strsql = "select id,objectguid,title,createdate,hitcount from document order by id desc";
  string cnstring = (new connection()).con

扫描关注微信公众号