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

首頁 > 開發 > 綜合 > 正文

顯示和隱藏DataGrid中的列

2024-07-21 02:23:08
字體:
來源:轉載
供稿:網友
要顯示和隱藏datagrid中的列,最關鍵的是autogeneratecolumns設置為false:下面就是實現這一功能的aspx代碼和腳本代碼:

<%@ page language="vb" autoeventwireup="false" codebehind="showhidecols.aspx.vb"
inherits="aspxweb.showhidecols"%>
<!doctype html public "-//w3c//dtd html 4.0 transitional//en">
<html>
<head>
<title>showhidecols</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">
<form id="form1" method="post" runat="server">
<asp:button id="btnshow" text="show details" onclick="showdetails" runat="server" />
<asp:button id="btnhide" text="hide details" onclick="hidedetails" runat="server" />
<asp:datagrid id="dtgcusts" runat="server" autogeneratecolumns="false"
bordercolor="#999999" borderstyle="none" borderwidth="1px" backcolor="white"
cellpadding="3" gridlines="vertical">
<columns>
<asp:boundcolumn datafield="title" />
<asp:boundcolumn datafield="id" visible="false" />
<asp:boundcolumn datafield="createdate" dataformatstring="{0:yyyy-mm-dd hh:mm:ss}"
visible="false" />
<asp:editcommandcolumn edittext="edit" headertext="edit" visible="false" />
</columns>
<alternatingitemstyle backcolor="#dcdcdc" />
<itemstyle forecolor="black" backcolor="#eeeeee" />
<headerstyle font-bold="true" forecolor="white" backcolor="#000084" />
</asp:datagrid>
</form>
</body>
</html>

后代碼腳本

imports system.data
imports system.data.oledb

public class showhidecols
inherits system.web.ui.page
protected withevents btnshow as system.web.ui.webcontrols.button
protected withevents btnhide as system.web.ui.webcontrols.button
protected withevents dtgcusts as system.web.ui.webcontrols.datagrid

#region " web 窗體設計器生成的代碼 "

'該調用是 web 窗體設計器所必需的。
<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: 此方法調用是 web 窗體設計器所必需的
'不要使用代碼編輯器修改它。
initializecomponent()
end sub

#end region

private sub page_load(byval sender as system.object, byval e as system.eventargs)_
handles mybase.load
'在此處放置初始化頁的用戶代碼
btnshow.text = "顯示列"
btnhide.text = "隱藏列"
dtgcusts.columns(1).headertext = ""
dtgcusts.columns(0).headertext = "標題"
dtgcusts.columns(2).headertext = "發布日期"
dtgcusts.columns(3).headertext = "編輯"
if not ispostback then
bindthedata()
end if
end sub

sub bindthedata()
dim objconn as oledbconnection
dim objcmd as oledbcommand
objconn = new oledbconnection("provider=microsoft.jet.oledb.4.0;data source=" _
+ server.mappath("test.mdb"))
dim strsql as string
strsql = "select top 10 id,title,createdate from document"
objcmd = new oledbcommand(strsql, objconn)
objconn.open()
dtgcusts.datasource = objcmd.executereader()
dtgcusts.databind()
objconn.close()
objconn.dispose()
end sub
sub showdetails(byval sender as system.object, byval e as system.eventargs)
dim intcounter as integer
for intcounter = 1 to dtgcusts.columns.count - 1
dtgcusts.columns(intcounter).visible = true
next
end sub

sub hidedetails(byval sender as system.object, byval e as system.eventargs)
dim intcounter as integer
for intcounter = 1 to dtgcusts.columns.count - 1
dtgcusts.columns(intcounter).visible = false
next
end sub

end class


發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 吴桥县| 旺苍县| 万宁市| 施秉县| 海口市| 武定县| 宣城市| 鸡东县| 招远市| 读书| 尤溪县| 泾源县| 沿河| 三亚市| 永川市| 蓝田县| 开阳县| 商丘市| 十堰市| 邹城市| 柏乡县| 开远市| 兴安县| 大宁县| 灵山县| 岑巩县| 昭平县| 嘉禾县| 平乐县| 衢州市| 巴东县| 南川市| 龙口市| 页游| 镇远县| 潢川县| 雅安市| 新绛县| 浮梁县| 白山市| 麻城市|