| Previous | Home | Next |
Gridview in ASP.NET
The GridView control displays data as a table and provides the capability to sort columns, page through data, and edit or delete a single record. the GridView control offers improvements such as the ability to define multiple primary key fields, improved user interface customization using bound fields and templates, and a new model for handling or canceling events.
Displays the values of a data source in a table where each column represents a field and each row represents a record. The GridView control enables you to select, sort, and edit these items.
Namespace: System.Web.UI.WebControls . Assembly: System.Web (in System.Web.dll).
GridView Control Features
- Enhanced data source binding capabilities (Direct interaction with Data Source with any writing any ADO.NET code)
- Built-in support for sorting and paging functionalities
- Improved Design time features(Smart Panel Tag)
- Customized pager user interface with PagerTemplate property.
- Additional Column types(ImageField).
- New Event model with support for pre event and post event operations
Difference between Datagrid,DataList and Data Repeater
- Datagrid has paging while Datalist doesnt.
- Datalist has a property called repeat. Direction = vertical/horizontal. (This is of great help in designing layouts). This is not there in Datagrid.
- A repeater is used when more intimate control over html generation is required.
- When only checkboxes/radiobuttons are repeatedly served then a checkboxlist or radio button list are used as they involve fewer overheads than a Datagrid.
Design of Gridview:

.VB Code
Imports System
.Data
Imports System
.Data.OleDb
Partial Class _Default
Inherits System.Web
.UI.Page
Protected Sub Page_Load(ByVal sender As Object,
ByVal e As System.EventArgs
) Handles Me.Load
Dim con As OleDbConnection
Dim da As OleDbDataAdapter
Dim conn As String = System.Configuration.ConfigurationManager
.AppSettings("x").ToString()
con = New OleDbConnection(conn)
da = New OleDbDataAdapter("select purchase1,tax,issue_date from purchase"
, con)
Dim ds As New DataSet()
da.Fill(ds, "purchase")
GridView1.DataSource = ds.Tables("purchase")
GridView1.DataBind()
End Sub
End Class
.ASPX Code
<%@ Page Language="VB"
AutoEventWireup="true"
CodeFile="Default.aspx.vb"
Inherits="_Default" %>
<!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 id="Head1"
runat="server">
<title>Untitled Page
</title>
<style type=
"text/css">
.style1 {
width: 100%;
}
</style>
</head>
<body>
<form id="form1"
runat="server">
<div>
<asp:GridView ID="GridView1" runat=
"server" AllowPaging="True"
BackColor="#DEBA84" BorderColor="#DEBA84"
BorderStyle="None"
BorderWidth="1px"
CellPadding="3"
CellSpacing=
"2" Height="341px"
onselectedindexchanged=
"GridView1_SelectedIndexChanged" Width=
"192px">
<FooterStyle BackColor=
"#F7DFB5" ForeColor=
"#8C4510" />
<RowStyle BackColor=
"#FFF7E7" ForeColor=
"#8C4510" />
<PagerStyle ForeColor=
"#8C4510" HorizontalAlign=
"Center" />
<SelectedRowStyle BackColor="#738A9C"
Font-
Bold="True"
ForeColor="White"
/>
<HeaderStyle BackColor="#A55129"
Font-Bold=
"True" ForeColor="White" />
</asp:GridView>
<table class
="style1">
<tr>
<td>
<marquee direction="up" behavior="scroll" onmouseover=
"this.stop()"
onmouseout="this.start()"
scrollamount=
"2" style=
"width: 383px">
<a href=
"#">Retail Express Distribution</a><br /><br />
<a href="#"
>Global Express Consolidation Service</a><br /><br />
<a href="#"
>Import Express </a><br /><br />
<a href="#"
>Collect charges and cash on delivery</a><br />
<br /></marquee> </td>
<td>
</td>
</tr>
<tr>
<td>
</td>
<td>
</td>
</tr>
</table>
</div>
</form>
</body>
</html>
| Previous | Home | Next |