Username: Password:

带图片的,多列的DropDownList的实现-.NET教程,数据库应用
来源:作者: 发布时间:2007-12-26 02:10:06

下面是模仿的dropdownlist的效果,支持图片,多列,换行等。查看例子

webdropdownlist.aspx

<%@ page language="c#" codebehind="webdropdownlist.aspx.cs"validaterequest="false"
autoeventwireup="false" inherits="emeng.webdropdownlist" %>


模拟下拉列表框





模拟下拉框















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
{
///
/// showlist 的摘要说明。
///

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()).connectionstring;
oledbconnection cn = new oledbconnection(cnstring);
cn.open();
oledbcommand cmd = new oledbcommand(strsql, cn);
datagrid1.datasource = cmd.executereader(commandbehavior.closeconnection);
datagrid1.databind();
cn.close();
cn.dispose();
cn = null;
cmd.dispose();
cmd = null;
}
catch(oledbexception myoledbexception)
{
response.write("错误:" + myoledbexception.message + ":" + myoledbexception.helplink);
response.end();
}
}
private void datagrid1_itemdatabound(object sender,system.web.ui.webcontrols.datagriditemeventargs e)
{

if( e.item.itemindex != -1 )
{
e.item.attributes.add("onmouseover", "this.bgcolor=#c1d2ee");
e.item.attributes.add("onclick",
"document.all.text1.innertext=this.cells[0].innertext;document.all.form1.city.value=this.cells[0].innertext;");
if (e.item.itemindex % 2 == 0 )
{
e.item.attributes.add("bgcolor", "#ffffff");
e.item.attributes.add("onmouseout", "this.bgcolor=document.getelementbyid(datagrid1).getattribute(singlevalue)");
}
else
{
e.item.attributes.add("bgcolor", "oldlace");
e.item.attributes.add("onmouseout", "this.bgcolor=document.getelementbyid(datagrid1).getattribute(oldvalue)");
}
}
else
{
datagrid1.attributes.add("oldvalue", "oldlace");
datagrid1.attributes.add("singlevalue", "#ffffff");
}
}
#region web form designer generated code
override protected void oninit(eventargs e)
{
//
// codegen:该调用是 asp.net web 窗体设计器所必需的。
//
initializecomponent();
base.oninit(e);
}

///
/// 设计器支持所需的方法 - 不要使用代码编辑器修改
/// 此方法的内容。
///

private void initializecomponent()
{
this.datagrid1.itemdatabound += new system.web.ui.webcontrols.datagriditemeventhandler(this.datagrid1_itemdatabound);
this.load += new system.eventhandler(this.page_load);
}
#endregion
}
}



喜欢本文,那就收藏到:

    Del.icio.us Google书签 Digg Live Bookmark Technorati Furl Yahoo书签 Facebook 百度搜藏 新浪ViVi 365Key网摘 天极网摘 和讯网摘 博拉网 POCO网摘 添加到饭否 QQ书签 Digbuzz我挖网
相关评论  我也要评论
还没有关于此文章的相关评论!
  • 昵称: (为空则显示guest)
  • 评论分数: ★ ★ ★★★ ★★★★ ★★★★★
  • 评论内容:(不能超过250字,需审核后才会公布,请自觉遵守互联网相关政策法规。
  • 导航
    赞助商
    文章类别
    订阅