vb.net_asp.net跨栏表头_滚动表体的DataGrid的实现
2024-07-10 13:00:54
供稿:网友
showfixheader.aspx
<%@ page language="vb" enableviewstate="false" autoeventwireup="false" codebehind="showfixheader.aspx.vb" inherits="vb1.showfixheader"%>
<!doctype html public "-//w3c//dtd html 4.0 transitional//en">
<html>
<head>
<title id="northsnow_title" runat="server"></title>
<meta name="generator" content="microsoft visual studio.net 7.0">
<meta name="code_language" content="visual basic 7.0">
<meta name="vs_defaultclientscript" content="javascript">
<meta name="vs_targetschema" content="http://schemas.microsoft.com/intellisense/ie5">
</head>
<body ms_positioning="gridlayout" leftmargin="0">
<table align="center">
<tr>
<td>
<form id="form1" method="post" runat="server">
<table id="table1" runat="server" cellspacing="1" cellpadding="2" width="720" border="1"
bgcolor="#cc6633" bordercolor="#cc9966" style="font-size:9pt;border-bottom:0px">
<tr align="center">
<td colspan="2" width="430"></td>
<td width="190" colspan="2"></td>
</tr>
<tr align="center">
<td width="360" bgcolor="#66cc99"></td>
<td width="180" bgcolor="white"></td>
<td width="140" bgcolor="#99cccc"></td>
<td width="40" bgcolor="#009999"></td>
</tr>
</table>
<div style="border:0px;padding:0px;margin:0px;overflow:auto;width:736px;height:200px">
<asp:datagrid id="datagrid1" width="720px" cellpadding="2" cellspacing="1"
bordercolor="#cc9966" font-size="9pt" alternatingitemstyle-backcolor="#6699ff"
runat="server" showheader="false" autogeneratecolumns="false">
<columns>
<asp:boundcolumn datafield="title">
<itemstyle width="360px"></itemstyle>
</asp:boundcolumn>
<asp:boundcolumn datafield="createdate">
<itemstyle width="180px" horizontalalign="center"></itemstyle>
</asp:boundcolumn>
<asp:boundcolumn datafield="author">
<itemstyle width="140px" horizontalalign="center"></itemstyle>
</asp:boundcolumn>
<asp:boundcolumn datafield="hitcount">
<itemstyle width="40px" horizontalalign="center"></itemstyle>
</asp:boundcolumn>
</columns>
</asp:datagrid>
</div>
</form>
</td>
</tr>
</table>
</body>
</html>
showfixheader.aspx.vb
imports system
imports system.data
imports system.data.oledb
public class showfixheader
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 northsnow_title as htmlcontrols.htmlgenericcontrol
#region " web form designer generated code "
'this call is required by the web form designer.
<system.diagnostics.debuggerstepthrough()> 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
northsnow_title.innertext = "northsnow home - 跨栏表头,滚动表体的datagrid的实现"
table1.rows(0).cells(0).innertext = "northsnow home article"
table1.rows(0).cells(1).innertext = "vb.net + asp.net"
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://blog.csdn.net/precipitant/')")
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 title,createdate,author,hitcount " + "from document 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 > 20 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, 20) + "…"
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