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

首頁 > 編程 > .NET > 正文

ASP.NET查詢ACCESS數據庫的內容并在DATAVIEW中顯示出來

2024-07-10 13:08:40
字體:
來源:轉載
供稿:網友

這篇文章中,就可以在dataview中顯示記錄了,但是如果你的字段名是英文或者你想設置一下dataview的樣式,使其更美觀,就不能使用這么簡單的代碼顯示了。
首先,如果要把標題顯示為漢字,那么需要設置dataview的autogeneratecolumns="false",不使用默認字段名,然后再設置asp:boundfield的headertext屬性,來改變列標題;另外可以設置headerstyle中的backcolor、font-size、horizontalalign等屬性,使其變得更加美觀。下面給一個我自己做的例子:

<%@ page language="vb" debug ="true"  %>
<%@ import namespace="system.data.oledb" %>
<!doctype html public "-//w3c//dtd xhtml 1.0 transitional//en" "http://www.w3.org/tr/xhtml1/dtd/xhtml1-transitional.dtd">

<script runat="server">
    dim connstr as string
    dim sql as string
    dim mycommand as oledbcommand
    dim myread as oledbdatareader
    dim conn as oledbconnection
    sub page_load(byval sender as object, byval e as eventargs)
        connstr = "provider=microsoft.jet.oledb.4.0;data source=" & server.mappath("rizhi.mdb") & ";user id=;password=;"
        conn = new oledbconnection(connstr)
        conn.open()
        sql = "select * from rizhi"
        mycommand = new oledbcommand(sql, conn)
        myread = mycommand.executereader()
       
        gridview1.datasource = myread
        gridview1.databind()
       
        'dim i as integer
        'do while myread.read()
        '    i = i + 1
        'loop
        'response.write(i)
    end sub
</script>

<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
    <title>無標題頁</title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
    <center>
        <asp:gridview id="gridview1" runat="server" autogeneratecolumns="false" width ="60%" font-size="12px" >
        <columns>
        <asp:boundfield datafield="id" headertext="序號" >
            <itemstyle font-size="12px" horizontalalign="left" />
            <headerstyle backcolor="burlywood" font-size="12px" horizontalalign="center" />
        </asp:boundfield>
       
        <asp:boundfield datafield="rq" headertext="日期" >
    <itemstyle font-size="12px" horizontalalign="left" />
    <headerstyle backcolor="burlywood" font-size="12px" horizontalalign="center" />
</asp:boundfield>

        <asp:boundfield datafield="n_je" headertext="金額" >
            <itemstyle font-size="12px" horizontalalign="right" />
            <headerstyle backcolor="burlywood" font-size="12px" horizontalalign="center" />
        </asp:boundfield>
       
        <asp:boundfield datafield="title" headertext="標題" >
            <itemstyle font-size="12px" horizontalalign="left" />
            <headerstyle backcolor="burlywood" font-size="12px" horizontalalign="center" />
        </asp:boundfield>
       
        <asp:boundfield datafield="content" headertext="內容" >
            <itemstyle font-size="12px" horizontalalign="left" />
            <headerstyle backcolor="burlywood" font-size="12px" horizontalalign="center" />
        </asp:boundfield>
       
        <asp:hyperlinkfield datatextfield="id" datanavigateurlfields ="id" datanavigateurlformatstring=" rizhi_edit.aspx?id={0} " headertext ="操作" datatextformatstring ="修改" >
        <itemstyle font-size="12px" horizontalalign="center" />
        <headerstyle backcolor ="burlywood" font-size="12px" horizontalalign="center" />
        </asp:hyperlinkfield>
        </columns>
        </asp:gridview>
    </center>      
    </div>
    </form>
</body>
</html>


值得注意的是,這里不光顯示了數據,而且還有一列是對數據的“操作”,當用戶點擊該列的時候,轉到修改頁面,并傳遞一個參數id,這里傳遞參數的方法是 datanavigateurlformatstring="<% rizhi_edit.aspx?id={0} %>" ,其中0表示第一個字段,1表示第二個字段,依此類推。


發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 三门县| 疏勒县| 子洲县| 正蓝旗| 瑞金市| 琼中| 辉县市| 明星| 滦平县| 肥东县| 花垣县| 灌阳县| 石渠县| 丹江口市| 南澳县| 体育| 湟中县| 兴宁市| 武义县| 湖南省| 盐池县| 黎平县| 江都市| 醴陵市| 湖南省| 封丘县| 安陆市| 武隆县| 定边县| 洪湖市| 玉山县| 樟树市| 洛宁县| 辽阳市| 龙江县| 荔浦县| 兴业县| 东山县| 乐至县| 三穗县| 确山县|