connectseekers.com

Thursday, 14 August 2014

GridView Bind By Using AccessDataSource in Asp.Net

8/14/2014 - By Pranav Singh 0

This article will show you how you can bind a gridview control for populating data using AccessDataSource in asp.net. In this we will not use c# code to bind the table detail to gridview.

Here is our db table


So for this article first we will create a new asp.net application and add a gridview control and AccessDataSource on .aspx page. After adding all the controls you page code will look as shown blow.

<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="GridViewByDataSource.aspx.cs" Inherits="ProjectDemo_Asp.et.GridViewByDataSource" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title>GridView Bind By Using AccessDataSource in Asp.Net</title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
   
        <asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False"
            DataSourceID="AccessDataSource1"
            EmptyDataText="There are no data records to display." Width="100%">
            <Columns>
                <asp:BoundField DataField="Id" HeaderText="Id" SortExpression="Id" />
                <asp:BoundField DataField="Name" HeaderText="Name" SortExpression="Name" />
                <asp:BoundField DataField="Address" HeaderText="Address"
                    SortExpression="Address" />
                <asp:BoundField DataField="Marks" HeaderText="Marks" SortExpression="Marks" />
            </Columns>
        </asp:GridView>
        <asp:AccessDataSource ID="AccessDataSource1" runat="server"
            DataFile="App_Data\bookstore.mdb"
            SelectCommand="SELECT `Id`, `Name`, `Address`, `Marks` FROM `Student`">
        </asp:AccessDataSource>
   
    </div>
    </form>
</body>
</html>

Here is the preview of the above  code.


Just check he above code

        <asp:AccessDataSource ID="AccessDataSource1" runat="server"
            DataFile="App_Data\bookstore.mdb"
            SelectCommand="SELECT `Id`, `Name`, `Address`, `Marks` FROM `Student`">
        </asp:AccessDataSource>

In this I have defined the datafile which is access database present in App_Data, and now the command query which is used for retrieving data from access database. This Accessdatasource have been defined to the gridview as a DataSourceId. Have a look of the App_Data folder.


So we have now run the page and check the output.


About the Author

We are the group of people who are expertise in different Microsoft technology like Asp.Net,MVC,C#.Net,VB.Net,Windows Application,WPF,jQuery,Javascript,HTML. This blog is designed to share the knowledge.

Get Updates

Subscribe to our e-mail newsletter to receive updates.

Share This Post

0 comments:

Please let me know your view

Free Ebooks


About Us

We are the group of people who are expertise in different Microsoft technology like Asp.Net,MVC,C#.Net,VB.Net,Windows Application,WPF,jQuery,Javascript,HTML. This blog is designed to share the knowledge.

Contact Us

For writing article in this website please send request by your

GMAIL ID: dotnetpools@gmail.com
Email Id : contact@aspdotnet-pools.com

Bugs and Suggestions

As we all know that this website is for sharing knowledge and providing proper solution. So while reading the article is you find any bug or if you have any suggestion please mail us at contact@aspdotnet-pools.com.

Partners


Top jQuery Plugins

Global Classified : Connectseekers.com
© 2014
back to top