<%@ Page Language="C#" Debug="true" %> <script runat="server"> AccessDataSource myDSource; string strSQL; void Page_Load(object sender, EventArgs e) { myDSource = new AccessDataSource(); myDSource.DataFile = "~/database/mydatabase.mdb"; if (!Page.IsPostBack) { BindData(); } } void BindData() { myDSource.SelectCommand = "SELECT * FROM [customer]"; //*** BindData to GridView ***' myGridView.DataSource = myDSource; myGridView.DataBind(); myDSource = null; } </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 ของทีมงานไทยครีเอท