国产探花免费观看_亚洲丰满少妇自慰呻吟_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


發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 女性| 和田市| 鹤岗市| 彭泽县| 会同县| 宿州市| 遂昌县| 荥经县| 乐亭县| 灌云县| 淮安市| 宽城| 佛学| 古田县| 临城县| 万宁市| 定襄县| 雅安市| 洪洞县| 澄江县| 龙口市| 罗平县| 昌邑市| 桐柏县| 康定县| 阿合奇县| 综艺| 卢龙县| 台北县| 广丰县| 卢湾区| 牡丹江市| 辰溪县| 乌拉特中旗| 南阳市| 白山市| 黄石市| 华蓥市| 达孜县| 孟连| 营山县|