创建固定表头、表格体滚动的DataGrid
[入库:2005年8月18日] [更新:2007年3月25日]
| 创建固定表头、表格体滚动的datagrid |
作者:孟宪会 出自:【孟宪会之精彩世界】 发布日期:2003年6月11日 7点49分48秒
|
|
在使用datagrid时,有时候需要表头表头固定、表格体的内容可以滚动,下面的代码就是实现这个功能的代码。
showfixedheader.aspx <%@ page language="vb" enableviewstate="false" autoeventwireup="false" codebehind="showfixedheader.aspx.vb"
inherits="aspxweb.mengxianhui.com.showfixedheader"%>
showfixedheader.aspx.vb imports system
imports system.data
imports system.data.oledb
public class showfixedheader
inherits system.web.ui.page
protected withevents table1 as system.web.ui.htmlcontrols.htmltable
protected withevents datagrid1 as system.web.ui.webcontrols.datagrid
protected withevents form1 as system.web.ui.htmlcontrols.htmlform
protected withevents lucky_elove as htmlcontrols.htmlgenericcontrol
#region " web form designer generated code "
'this call is required by the web form designer.
private sub initializecomponent()
end sub
private sub page_init(byval sender as system.object, byval e as system.eventargs) handles mybase.init
'codegen: this method call is required by the web form designer
'do not modify it using the code editor.
initializecomponent()
end sub
#end region
private sub page_load(byval sender as system.object, byval e as system.eventargs) handles mybase.load
lucky_elove.innertext = "【孟宪会之精彩世界】 - 跨栏表头的实现"
table1.rows(0).cells(0).innertext = "【孟宪会之精彩世界】.net版本之最新文章"
table1.rows(0).cells(1).innertext = "文章信息"
table1.rows(1).cells(0).innertext = "文章标题"
table1.rows(1).cells(1).innertext = "发布时间"
table1.rows(1).cells(2).innertext = "所属栏目"
table1.rows(1).cells(3).innertext = "点击率"
table1.rows(0).style.add("color", "white")
table1.rows(0).style.add("font-weight", "bold")
table1.rows(0).cells(0).attributes.add("onclick",_
"window.open('http://lucky_elove.www1.dotnetplayground.com/')")
table1.rows(0).cells(0).style.add("cursor", "hand")
try
dim cnstring as string = "provider=microsoft.jet.oledb.4.0;data source="_
+ server.mappath("test.mdb")
dim cn as new oledbconnection(cnstring)
cn.open()
dim strsql as string = "select top 30 d.title,d.createdate,s.title as pid,d.hitcount "_
+ "from document d inner join subject s on d.pid = s.id order by createdate desc"
dim cmd as new oledbcommand(strsql, cn)
datagrid1.datasource = cmd.executereader
datagrid1.databind()
cn.close()
cn = nothing
catch eole as oledbexception
response.write("产生错误:" + eole.message)
end try
end sub
private sub datagrid1_itemdatabound(byval sender as object, _
byval e as system.web.ui.webcontrols.datagriditemeventargs) handles datagrid1.itemdatabound
if e.item.itemtype = listitemtype.item or e.item.itemtype = listitemtype.alternatingitem then
if e.item.cells(0).text.length > 26 then
e.item.cells(0).attributes.add("title", e.item.cells(0).text)
e.item.cells(0).text = e.item.cells(0).text.substring(0, 26) + "…"
end if
e.item.cells(1).text = format(system.convert.todatetime(e.item.cells(1).text),_
"yyyy年m月d日 h点m分s秒")
end if
end sub
end class
结果如下:

|
本文关键:创建固定表头、表格体滚动的DataGrid
本站最佳浏览方式为 分辨率 1024x768 IE 6.0(或更高版本的 IE浏览器)