Asp.net programming we consider all important topic for knowledge about controls,web Services, JSON, Ajax, database, and interview related Question. In this Asp.net and sql server tutorial blog we give many examples of jquery as like How Play YouTube Video in Your Asp.net Website by URL, How to Play YouTube Videos in Asp.net by using Jquery , Jquery Change div background on mouseover in asp.net , JQuery UI Datepicker (Calendar) etc.

Wednesday, August 13, 2014

Introduction of Asp.net Grid View Control

GridView in Asp.net:
As we know that the grid view control is very important of every ASP.NET webpage, for displaying rows of data and allow to user to add records, edit records and delete records. Grid is use to display data in tabular format (in the form of rows and columns).

GridView on webpage:

Create GridView on webpage by drag and drop the control from toolbox on ASP.NET web page ,the code is auto generated or you can write fallowing code for make grid on page.

<asp:GridView ID="grid1" runat="server" Height="292px" Width="914px" >
</asp:GridView>

Gridview control
Gridview control

Grid control with header Style:

<asp:GridView ID="grid1" runat="server" BorderColor="#990000"
            BorderStyle="Groove" BorderWidth="1px" Height="292px" Width="787px" >
            <HeaderStyle BackColor="#3333FF" BorderColor="#000099" BorderStyle="Groove"
                BorderWidth="1px" />
        </asp:GridView>

Grid with Footer and header Style:

<asp:GridView ID="grid1" runat="server" BorderColor="#990000"
            BorderStyle="Groove" BorderWidth="1px" Height="292px" ShowFooter="True"
            Width="787px" >
            <FooterStyle BackColor="#3399FF" BorderColor="#0000CC" BorderStyle="Groove"
                BorderWidth="1px" HorizontalAlign="Center" VerticalAlign="Middle" />
            <HeaderStyle BackColor="#3333FF" BorderColor="#000099" BorderStyle="Groove"
                BorderWidth="1px" />
        </asp:GridView>
Asp.net Grid with header
Asp.net Grid with header and footer


Gridview Constructors in Asp.net :

This is use to create a new grid instance of control. Initialization of control as fallows-
GridView MyGrid = new GridView();


Grid Properties: 

There are fallowing Properties of Asp.net Grid we consider here –
  • Access Key: For Quick Navigation. This is inherited by Web control class.
  • AllowPaging: Paging feature is enabled.
  • AllowSorting: Sorting feature is enabled.
  • AlternatingRowStyle: Enables you to set the appearance of alternating data rows in a Grid .
  • AppRelativeTemplateSourceDirectory: Inherited from Control class.
  • BackColor: Define Background color of the Web server control.
  • BackImageUrl: Image to display in the background of Grid control.

Many other asp Grid properties are BindingContainer, BorderColor, BorderStyle, BorderWidth, BottomPagerRow, Caption, CaptionAlign, ForeColor, GridLines, HasAttributes, HeaderRow, HeaderStyle, Height, HorizontalAlign, IsViewStateEnabled etc.


Asp.Net GridView Methods:

  •         DataBinding:  when control binds to a data source.
  •         DataBound:  after control binds to a data source.
  •         Disposed: control is released from memory.
  •         Init: control is initialized, this is the first step in its server control lifecycle.
  •         Load: control is loaded into the Page object.
  •         PageIndexChanged: Pager buttons is clicked.
  •         PreRender: after the Control object is loaded but prior to rendering.
  •         RowCancelingEdit: Cancel button of a row in edit mode is clicked.
  •         RowCommand:  when a button is clicked in a Grid control.
  •         RowCreated: when a row is created in a control Grid.
  •         RowDataBound : when a data row is bound to data in a GridView.
  •         RowDeleted: when a row's Delete button is clicked.       
  •         RowEditing: when a row's Edit button is clicked.
  •         RowUpdated: when a row's Update button is clicked.

             Many other asp Grid properties are SelectedIndexChanged, SelectedIndexChanging, Sorted,Unload etc.

Syntax of Grid view with possible Properties and Events:

<asp:GridView AccessKey="string" AllowPaging=" Boolen " AllowSorting=" Boolen "            AutoGenerateColumns=" Boolen " AutoGenerateDeleteButton=" Boolen " AutoGenerateEditButton=" Boolen " AutoGenerateSelectButton=" Boolen " BackColor="color name|#dddddd" BackImageUrl="uri" BorderColor="color name|#dddddd" BorderStyle="NotSet|None|Dotted|Dashed|Solid|Double|Groove|Ridge|Inset|Outset" BorderWidth="size" Caption="string" CaptionAlign="NotSet|Top|Bottom|Left|Right"
CellPadding="integer" CellSpacing="integer" CssClass="string" DataKeyNames="string"
DataMember="string" DataSource="string" DataSourceID="string" EditIndex="integer"
EmptyDataText="string" Enabled=" Boolen " EnableSortingAndPagingCallbacks=" Boolen "
EnableTheming=" Boolen " EnableViewState=" Boolen " Font-Bold=" Boolen "
Font-Italic=" Boolen " Font-Names="string" Font-Overline=" Boolen " Font-Size="string|Smaller|Larger|XX-Small|X-Small|Small|Medium|Large|X-Large|XX-Large"
Font-Strikeout=" Boolen " Font-Underline=" Boolen " ForeColor="color name|#dddddd"
GridLines="None|Horizontal|Vertical|Both" Height="size" HorizontalAlign="NotSet|Left|Center|Right|Justify" ID="string" OnDataBinding="DataBinding event handler" OnDataBound="DataBound event handler" OnDisposed="Disposed event handler" OnInit="Init event handler" OnLoad="Load event handler"   OnPageIndexChanged="PageIndexChanged event handler" OnPageIndexChanging="PageIndexChanging event handler"
OnPreRender="PreRender event handler" OnRowCancelingEdit="RowCancelingEdit event handler"
OnRowCommand="RowCommand event handler" OnRowCreated="RowCreated event handler"
OnRowDataBound="RowDataBound event handler" OnRowDeleted="RowDeleted event handler"
OnRowDeleting="RowDeleting event handler" OnRowEditing="RowEditing event handler"
OnRowUpdated="RowUpdated event handler" OnRowUpdating="RowUpdating event handler"
OnSelectedIndexChanged="SelectedIndexChanged event handler" OnSelectedIndexChanging="SelectedIndexChanging event handler"
OnSorted="Sorted event handler" OnSorting="Sorting event handler" OnUnload="Unload event handler" PageIndex="integer" PagerSettings-FirstPageImageUrl="uri" PagerSettings-FirstPageText="string" PagerSettings-LastPageImageUrl="uri" PagerSettings-LastPageText="string" PagerSettings-Mode="NextPrevious" PagerSettings-NextPageImageUrl="uri" PagerSettings-NextPageText="string"
PagerSettings-PageButtonCount="integer" PagerSettings-Position="Bottom|Top|TopAndBottom"
PagerSettings-PreviousPageImageUrl="uri" PagerSettings-PreviousPageText="string"
PagerSettings-Visible=" Boolen " PageSize="integer" RowHeaderColumn="string"
runat="server" SelectedIndex="integer" ShowFooter=" Boolen " ShowHeader=" Boolen "
SkinID="string" Style="string" TabIndex="integer" ToolTip="string" UseAccessibleHeader=" Boolen " Visible=" Boolen " Width="size">
</asp:GridView> 

GridView control Features :

GridView control supports the following features, they are
  • Binding to data source controls, such as SqlDataSource.
  • Multiple data fields for the hyperlink columns.
  • Built-in paging capabilities.
  • Built-in sort capabilities.
  • Built-in row selection capabilities.
  • Built-in update and delete capabilities.
  • Customizable appearance through themes and styles.
  • Multiple key fields.
  • Programmatic access to the GridView object model to dynamically set properties.

Other Asp.net Controls:


Other Asp.net Related Post: 

No comments:

Post a Comment