<%@ Page Language="VB" %> <script runat="server"> Dim myDSource As AccessDataSource Dim strSQL As String Sub Page_Load(sender As Object, e As EventArgs) myDSource = New AccessDataSource() myDSource.DataFile = "~/database/mydatabase.mdb" IF Not Page.IsPostBack() Then BindData() End IF End Sub Sub BindData() With myDSource .SelectCommand = "SELECT * FROM [customer]" End With '*** BindData to GridView ***' myGridView.DataSource = myDSource myGridView.DataBind() myDSource = Nothing End Sub </script> <html> <head> <title>ThaiCreate.Com ASP.NET - AccessDataSource</title> </head> <body> <form id="form1" runat="server"> <asp:GridView id="myGridView" runat="server" AutoGenerateColumns="False"> <Columns> <asp:TemplateField HeaderText="CustomerID"> <ItemTemplate> <asp:Label id="lblCustomerID" runat="server" Text='<%# DataBinder.Eval(Container, "DataItem.CustomerID") %>'></asp:Label> </ItemTemplate> </asp:TemplateField> <asp:TemplateField HeaderText="Name"> <ItemTemplate> <asp:Label id="lblName" runat="server" Text='<%# DataBinder.Eval(Container, "DataItem.Name") %>'></asp:Label> </ItemTemplate> </asp:TemplateField> <asp:TemplateField HeaderText="Email"> <ItemTemplate> <asp:Label id="lblEmail" runat="server" Text='<%# DataBinder.Eval(Container, "DataItem.Email") %>'></asp:Label> </ItemTemplate> </asp:TemplateField> <asp:TemplateField HeaderText="CountryCode"> <ItemTemplate> <asp:Label id="lblCountryCode" runat="server" Text='<%# DataBinder.Eval(Container, "DataItem.CountryCode") %>'></asp:Label> </ItemTemplate> </asp:TemplateField> <asp:TemplateField HeaderText="Budget"> <ItemTemplate> <asp:Label id="lblBudget" runat="server" Text='<%# DataBinder.Eval(Container, "DataItem.Budget") %>'></asp:Label> </ItemTemplate> </asp:TemplateField> <asp:TemplateField HeaderText="Used"> <ItemTemplate> <asp:Label id="lblUsed" runat="server" Text='<%# DataBinder.Eval(Container, "DataItem.Used") %>'></asp:Label> </ItemTemplate> </asp:TemplateField> </Columns> </asp:GridView> </form> </body> </html>
ช่วยกันสนับสนุนรักษาเว็บไซต์ความรู้แห่งนี้ไว้ด้วยการสนับสนุน Source Code 2.0 ของทีมงานไทยครีเอท