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.
Some of my previous articles on gridview are as follows:
Binding
Gridview By Access DataBase Using C#.Net in Asp.Net, Validate
Selection Of Checkbox In GirdView Using Asp.net C# and jQuery | Force User To
Select One CheckBox Of GridView Before Submit in Asp.net Using javascript, How
To Make a Single Row of DataGridview Bold Using C#.Net in Windows Application,
GridView
- Delete Selected Row Record From DataBase On Button Click in Asp.net Using
C#.Net, Drag
Drop Cells in GridView Control Using Asp.net C# and jQuery, Highlight
GridView Row on Mouseover Using CSS in Asp.Net C#.Net, Code to
Export GridView to PDF in Asp.Net Using C# and Vb.Net, Bind DataGridView In
Windows Application Using C#, How
to Bind Data To TextBox Values in Asp.Net GridView Control Using C#.Net.
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.
0 comments:
Please let me know your view