access|asp.net| Data | database | display
In this article, you can display the record in the DataView, but if your field name is English or you want to set the DataView style to make it more beautiful, you can't use such a simple code.
First, if you want to display the title as Chinese characters, you need to set the DataView autogeneratecolumns= "false", not using the default field name, and then setting the Asp:boundfield HeaderText property to change the column heading In addition, the BackColor, Font-size, horizontalalign and other attributes can be set up in HeaderStyle to make it more beautiful. Here's a sample I made myself:
<%@ 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>
<title> Untitled Page </title>
<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= "serial number" >
<itemstyle font-size= "12px" horizontalalign= "left"/>
</asp:BoundField>
<asp:boundfield datafield= "RQ" headertext= "date" >
<itemstyle font-size= "12px" horizontalalign= "left"/>
</asp:BoundField>
<asp:boundfield datafield= "N_je" headertext= "Amount" >
<itemstyle font-size= "12px" horizontalalign= "right"/>
</asp:BoundField>
<asp:boundfield datafield= "title" headertext= "Titles" >
<itemstyle font-size= "12px" horizontalalign= "left"/>
</asp:BoundField>
<asp:boundfield datafield= "Content" headertext= "Contents" >
<itemstyle font-size= "12px" horizontalalign= "left"/>
</asp:BoundField>
<asp:hyperlinkfield datatextfield= "id" datanavigateurlfields = "id" datanavigateurlformatstring= "rizhi_edit.aspx ? id={0} "HeaderText = action" datatextformatstring = "Modify" >
<itemstyle font-size= "12px" horizontalalign= "Center"/>
</asp:HyperLinkField>
</Columns>
</asp:GridView>
</center>
</div>
</form>
</body>
It is worth noting that not only the data is shown here, but also a column is the "operation" of the data, when the user clicks on the column, go to modify the page, and pass a parameter ID, where the method of passing parameters is datanavigateurlformatstring= "<% Rizhi _edit.aspx?id={0}%>, where 0 represents the first field, 1 represents the second field, and so on.