Skip to main content

GridView Control and their properties, methods and events in ASP.NET

The GridView control is a data bound control that displays the values of a data source in the form of a table. In this table, each column represents a field and each row represents a record. The GridView control exists within the System.Web.UI .Controls namespace.

When you drag and drop the GridView control on the designer page, the following syntax is added to the source view of the page:
<asp:GridView ID="GridView1" runat="server"> </asp:GridView>

The GridView data control has a built-in capability of sorting, paging, updating, and deleting data. You can also set the column fields through the AutoGenerate property to indicate whether bound fields are automatically created for each field in the data source.

Column fields types of the GridView class

BoundField:   Shows the value of a field in a data source. It is the default column type of the GridView control.
ButtonField:   Shows a command button for each item in the GridView control. It allows to create a column of custom button controls, such as the Add or the Remove button.

CheckBoxField:  Shows a CheckBox control for each item in the GridView control. This column field type is commonly used to display fields with a Boolean value.

CommandField:  Shows predefined command buttons to perform operations, such as select, edit, or delete.
HyperLinkField:    Shows the value of a field in a data source as a hyperlink. This column field type allows you to bind a second field to the hyperlink's URL.

ImageField:            Shows an image for each item in the GridView control.
TemplateField:    Shows user-defined content for each item in the GridView control according to a specified template. This column field type enables us to create a custom column field.

You can also customize the appearance of the GridView control by setting the style properties

EditRowStyle: Performs the style settings for the row that is edited in the GridView control.
EmptyDataRowStyle: Performs the style settings for the empty data row displayed in the GridView control when the data source does not contain any records.
FooterStyle: Performs the style settings for the footer row of the GridView control.
HeaderStyle: Performs the style settings for the header tow of the GridVxew control.
PagerStyle: Performs the style settings for the pager row of the GridView control.
SelectedRowStyle: Performs the style settings for the selected row in the GridView control.

Properties of the GridView Class

AllowPaging: Obtains or sets a value indicating whether the paging feature is enabled.
AllowSorting: Obtains or sets a value indicating whether the sorting feature is enabled.
AlternatingRowStyle: Obtains a reference to the TableltemStyle object that enables us to set the appearance of alternating data rows in a GridView control.
AutoGenerateColumns: Obtains or sets a value indicating whether bound fields are automatically created for each field in the data source.
AutoGenerateDeleteButton: Obtains or sets a value indicating whether a CommandField field column with a Delete button for each data row is automatically added to a GridView control.
AutoGenerateEditButton: Obtains or sets a value indicating whether a CommandField field column with an Edit button for each data row is automatically added to a GridView control.
AutoGenerateSelectButton: Obtains or sets a value indicating whether a CommandField field column with a Select button for each data row is automatically added to a GridView control.
BacklmageUrl: Obtains or sets the URL to an image to display in the background of a GridView control.
BottomPagerRow: Obtains a GridViewRow object that represents the bottom pager row in a GridView control.
Caption; Obtains or sets the text to render in an HTML caption element in a GridView control. This property is provided to make the control more accessible to users of assistive technology devices.
CaptionAlign: Obtains or setsthe horizontal or vertical position of the HTML caption element in a GridView control. This property is provided to make the control more accessible to users of assistive technology devices.
CellPadding: Obtains or sets the amount of space between the contents of a cell and the cell's border.
Cellspacing: Obtains or sets the amount of space between cells.
Columns: Obtains a collection of DataControlField objects that represent the column fields
in a GridView control.
DataKeyNames: Obtains or sets an array that contains the names of the primary key fields for the items displayed in a GridView control.
DataKeys: Obtains a collection of DataKey objects that represent the data key value of each row in a GridView control.
Editlndex:  Obtains or sets the index of the row to edit.
EditRowStyle: Obtains a reference to the TableltemStyle object that enables us to set the appearance of the row selected for editing in a GridView control.
EmptyDataRowStyle: Obtains a reference to the TableltemStyle object that enables us to set the appearance of the empty data row rendered when a GridView control is bound to a data source that does not contain any records.
EmptyDataTemplate: Obtains or sets the user-defined content for the empty data row rendered when a GridView control is bound to a data source that does not contain any records.
EmptyDataText: Obtains or sets the text to display in the empty data row rendered when a GridView control is bound to a data source that does not contain any records.

EnableSortingAndPagingCallbacks: Obtains or sets a value indicating whether client-side callbacks are used for sorting and paging operations.
FooterRow: Obtains a GridViewRow object that represents the footer row in a GridView control.
FooterStyle: Obtains a reference to the TableltemStyle object that enables us to set the appearance of the footer row inaGridView control.
GridLines: Obtains or sets the gridline style for a GridView control.
HeaderRow: Obtains a GridViewRow object that represents the header row in a GridView control.
HeaderStyle: Obtains a reference to the TableltemStyle object that enables us to set the appearance of the header row in a GridView control.
HorizontalAlign: Obtains or sets the horizontal alignment of a GridView control on the page.
PageCount: Obtains the number of pages required to display the records of the data source in a GridView control.
Pagelndex: Obtains or sets the index of the currently displayed page.
PagerSettings: Obtains a reference to the PagerSettings object that enables us to set the properties of the pager buttons in a GridView control.
PagerStyle: Obtains a reference to the TableltemStyle object that enables us to set the appearance of the pager row in a GridView control.
PagerTemplate: Obtains or sets the custom content for the pager row in a GridView control.
PageSize: Obtains or sets the number of records to display on a page in a GridView control.
RowHeaderColumn: Obtains or sets the name of the column to use as the column header for the GridView control. This property is provided to make the control more accessible to users of assistive technology devices.
Rows: Obtains a collection of GridViewRow objects that represent the data rows in a GridView control.
RowStyle: Obtains a reference to the TableltemStyle object that enables us to set the appearance of the data rows in a GridView control.
SelectedDataKey: Obtains the DataKey object that contains the data key value for the selected row in a GridView control.
Selectedlndex: Obtains or sets the index of the selected row in a GridView control.
SelectedRow: Obtains a reference to a GridViewRow object that represents the selected row in the control.
SelectedRowStyle: Obtains a reference to the TableltemStyle object that enables us to set the appearance of the selected row in a GridView control.
SelectedValue: Obtains the data key value of the selected row in a GridView control.
ShowFooter: Obtains or sets a value showing whether the footer row is displayed in a GridView control.
ShowHeader: Obtains or sets a value showing whether the header row is displayed in a GridView control.
SortDirection Obtains the sort direction of the column being sorted.
SortExpression Obtains the sort expression associated with the column or columns being sorted.
TopPagerRow Obtains a GridViewRow object that represents the top pager row in a GridView control.
UseAccessibleHeader Obtains or sets a value indicating whether a GridView control renders its header in an accessible format. This property makes the control more accessible to users of assistive technology devices.

Methods of the GridView Class

DataBind: Binds the data source to the GridView control
DeleteRow: Deletes the record at the specified index from the data source
IsBindableType: Determines whether the specified data type can be bound to a column in a GridView control
Sort: Sorts the GridView control based on the specified sort expression and direction
UpdateRow: Updates the record at the specified row index using the field values of the row

Events of the GridView Class

PagelndexChanged: Invoked when one of the pager buttons is clicked after the GridView control handles the paging operation
PagelndexChanging: Invoked when one of the pager buttons is clicked, but before the GridView control handles the paging operation
RowCancelingEdit: Invoked when the Cancel button of a row in edit mode is clicked, but before the row exits the edit mode
RowCommand: Invoked when a button is clicked in a GridView control.
RowCreated:         Invoked when a row is created in a GridView control
RowDataBound: Invoked when a data row is bound to data in a GridView control
RowDeleted: Invoked when a row's Delete button is clicked, but after the GridView control deletes the row
RowDeleting: Invoked when a row's Delete button is clicked, but before the GridView control deletes the row
RowEditing: Invoked when a row's Edit button is clicked, but before the GridView control enters edit mode
RowUpdated: Invoked when a row's Update button is clicked, but after the GridView control updates the row
RowUpdating: Invoked when a row's Update button is clicked, but before the GridView control updates the row
SelectedlndexChanged: Invoked when a row's Select button is clicked, but after the GridView control handles the select operation
SelectedlndexChanging: Invoked when a row's Select button is clicked, but before the GridView control handles the select operation.
Sorted: Invoked when the hvperlink to sort a column is clicked, but after the GridView control handles the sort operation
Sorting: Invoked when the hyperlink to sort a column is clicked, but before the GridView control handles the sort operation

Comments

Popular posts from this blog

difference between structure and union in C Language

In c language article we will see the difference between union and structure. Both are the user define datatype in c language. See the table which is mentioned below: ASP.NET Video Tutorial Series Structure Union1.The keywordstruct is used to define a structure 1. The keyword union is used to define a union. 2. When a variable is associated with a structure, the compiler allocates the memory for each member. The size of structure is greater than or equal to the sum ofsizes of its members. The smaller members may end with unused slack bytes. 2. When a variable is associated with a union, thecompiler allocates thememory by considering the size of the largest memory. So, size of union is equal to the size of largest member. 3. Each member within a structure is assigned unique storage area of location. 3. Memory allocated is shared by individual members of union. 4. The address of each member will be in ascending order This indicates that memory for each member will start at different offset v…

Difference between Linear search and Binary Search in c language

SQL Video Channel : Download all SQL Video



Binary Search Linear Search Works only on sorted items. such as  1,2,3,4,5,6  etc
Works on sorted as well as unsorted items. 12,4,5,3,2,1 etc Very efficient if the items are sorted Very efficient if the items are less and present in the beginning of the list. such as Suppose your list items are : 12,3,4,5,1 and you want to search 12 number then you get beginning in the list. Works well with arrays and not on linked lists. Works with arrays and linked lists.
Number of comparisons are less More number of comparisons are required if the items are present in the later part of the array or its elements are more.

Memory representation of Linked List Data Structures in C Language

Memory representation of Linked List

             In memory the linked list is stored in scattered cells (locations).The memory for each node is allocated dynamically means as and when required. So the Linked List can increase as per the user wish and the size is not fixed, it can vary.

               Suppose first node of linked list is allocated with an address 1008. Its graphical representation looks like the figure shown below:


      Suppose next node is allocated at an address 506, so the list becomes,



  Suppose next node is allocated with an address with an address 10,s the list become,


The other way to represent the linked list is as shown below:




 In the above representation the data stored in the linked list is “INDIA”, the information part of each node contains one character. The external pointer root points to first node’s address 1005. The link part of the node containing information I contains 1007, the address of next node. The last node …