国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 開發(fā) > 綜合 > 正文

創(chuàng)建跨多列、多行表頭的DataGrid

2024-07-21 02:23:06
字體:
供稿:網(wǎng)友
在使用datagrid時,有時候需要表頭跨列、多行,下面的代碼就是實(shí)現(xiàn)這個功能的代碼。

查看例子

showcolspanheader.aspx

<%@ page language="vb" autoeventwireup="false" codebehind="showcolspanheader.aspx.vb"
inherits="aspxweb.mengxianhui.com.showcolspanheader"%>
<!doctype html public "-//w3c//dtd html 4.0 transitional//en">
<html>
<head>
<title id="lucky_elove" 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">
<form id="form1" method="post" runat="server">
<table id="table1" runat="server" cellspacing="1" cellpadding="2" width="780" border="1"
bgcolor="#cc6633" bordercolor="#cc9966" style="font-size:9pt;border-bottom:0px">
<tr align="center">
<td colspan="2" width="580"></td>
<td width="200" colspan="2"></td>
</tr>
<tr align="center">
<td width="400" bgcolor="#66cc99"></td>
<td width="180" bgcolor="white"></td>
<td width="160" bgcolor="#99cccc"></td>
<td width="40" bgcolor="#009999"></td>
</tr>
</table>
<asp:datagrid id="datagrid1" width="780px" alternatingitemstyle-backcolor="#6699ff"
cellpadding="2" cellspacing="1" borderwidth="1" bordercolor="#cc9966" font-size="9pt"
runat="server" showheader="false" autogeneratecolumns="false">
<columns>
<asp:boundcolumn datafield="title">
<itemstyle width="400px"></itemstyle>
</asp:boundcolumn>
<asp:boundcolumn datafield="createdate">
<itemstyle width="180px"></itemstyle>
</asp:boundcolumn>
<asp:boundcolumn datafield="pid">
<itemstyle width="160px"></itemstyle>
</asp:boundcolumn>
<asp:boundcolumn datafield="hitcount">
<itemstyle width="40px"></itemstyle>
</asp:boundcolumn>
</columns>
</asp:datagrid>
</form>
</body>
</html>

showcolspanheader.aspx.vb

imports system
imports system.data
imports system.data.oledb

public class showcolspanheader
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 lucky_elove 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
lucky_elove.innertext = "【孟憲會之精彩世界】 - 跨欄表頭的實(shí)現(xiàn)"
table1.rows(0).cells(0).innertext = "【孟憲會之精彩世界】.net版本之最新文章"
table1.rows(0).cells(1).innertext = "文章信息"
table1.rows(1).cells(0).innertext = "文章標(biāo)題"
table1.rows(1).cells(1).innertext = "發(fā)布時間"
table1.rows(1).cells(2).innertext = "所屬欄目"
table1.rows(1).cells(3).innertext = "點(diǎn)擊率"
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 20 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("產(chǎn)生錯誤:" + 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) + "&#8230;"
end if
e.item.cells(1).text=format(system.convert.todatetime(e.item.cells(1).text),"yyyy年m月d日 h點(diǎn)m分s秒")
end if
end sub
end class

  • 本文來源于網(wǎng)頁設(shè)計愛好者web開發(fā)社區(qū)http://www.html.org.cn收集整理,歡迎訪問。
  • 發(fā)表評論 共有條評論
    用戶名: 密碼:
    驗(yàn)證碼: 匿名發(fā)表
    主站蜘蛛池模板: 嫩江县| 泸州市| 宝坻区| 遵义市| 项城市| 江油市| 乌鲁木齐市| 哈密市| 广水市| 大安市| 屏山县| 嵊州市| 夏津县| 都江堰市| 土默特右旗| 基隆市| 宝山区| 东至县| 山东省| 彰化市| 铜梁县| 吴川市| 永城市| 德庆县| 岢岚县| 革吉县| 崇仁县| 丰台区| 海丰县| 阜康市| 宣威市| 桦南县| 普兰县| 哈密市| 资讯 | 德昌县| 南京市| 临汾市| 巴林左旗| 绥滨县| 唐山市|