Asp. NET queries the contents of an Access database and displays it in DataView

Source: Internet
Author: User
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.



Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.