国产探花免费观看_亚洲丰满少妇自慰呻吟_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表示第二個字段,依此類推。


發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 沈丘县| 库车县| 德令哈市| 蒙山县| 荆州市| 五指山市| 台东县| 双桥区| 南平市| 东光县| 陆丰市| 柏乡县| 洮南市| 德安县| 綦江县| 昭苏县| 镇赉县| 东兰县| 商洛市| 连州市| 泽库县| 富宁县| 秦皇岛市| 定陶县| 榕江县| 武隆县| 周至县| 孟津县| 晋宁县| 库伦旗| 三穗县| 汉寿县| 桐梓县| 阿勒泰市| 阜城县| 遂昌县| 曲靖市| 黄浦区| 永州市| 正宁县| 涪陵区|