ASP.NET(vb.net) AccessDataSource & GridView Example code how to use ASP.NET and AccessDataSource for create DataSource and bind data to GridView
ShotDev Focus:
- ASP.NET(vb.net) AccessDataSource & GridView
Example
AspNetAccessDataSourceGridView.aspx
<%@ 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>ShotDev.Com Tutorial</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>
Create a asp.net file and save to path root-path/dotnet/
Run
http://localhost/dotnet/AspNetAccessDataSourceGridView.aspx
Screenshot