Export (0) Print
Expand All

WebGrid Class

Displays data on a web page using an HTML table element.

System.Object
  System.Web.Helpers.WebGrid

Namespace:  System.Web.Helpers
Assembly:  System.Web.Helpers (in System.Web.Helpers.dll)

public class WebGrid

The WebGrid type exposes the following members.

  NameDescription
Public methodWebGridInitializes a new instance of the WebGrid class.
Top

  NameDescription
Public propertyAjaxUpdateCallbackGets the name of the JavaScript function to call after the HTML element that is associated with the WebGrid instance has been updated in response to an Ajax update request.
Public propertyAjaxUpdateContainerIdGets the value of the HTML id attribute that marks an HTML element on the web page that gets dynamic Ajax updates that are associated with the WebGrid instance.
Public propertyColumnNamesGets a collection that contains the name of each data column that is bound to the WebGrid instance.
Public propertyFieldNamePrefixGets the prefix that is applied to all query-string fields that are associated with the WebGrid instance.
Public propertyHasSelectionGets a value that indicates whether a row in the WebGrid instance is selected.
Public propertyPageCountGets the number of pages that the WebGrid instance contains.
Public propertyPageFieldNameGets the full name of the query-string field that is used to specify the current page of the WebGrid instance.
Public propertyPageIndexGets or sets the index of the current page of the WebGrid instance.
Public propertyRowsGets a list that contains the rows that are on the current page of the WebGrid instance after the grid has been sorted.
Public propertyRowsPerPageGets the number of rows that are displayed on each page of the WebGrid instance.
Public propertySelectedIndexGets or sets the index of the selected row relative to the current page of the WebGrid instance.
Public propertySelectedRowGets the currently selected row of the WebGrid instance.
Public propertySelectionFieldNameGets the full name of the query-string field that is used to specify the selected row of the WebGrid instance.
Public propertySortColumnGets or sets the name of the data column that the WebGrid instance is sorted by.
Public propertySortDirectionGets or sets the direction in which the WebGrid instance is sorted.
Public propertySortDirectionFieldNameGets the full name of the query-string field that is used to specify the sort direction of the WebGrid instance.
Public propertySortFieldNameGets the full name of the query-string field that is used to specify the name of the data column that the WebGrid instance is sorted by.
Public propertyTotalRowCountGets the total number of rows that the WebGrid instance contains.
Top

  NameDescription
Public methodBindBinds the specified data to the WebGrid instance.
Public methodColumnCreates a new WebGridColumn instance.
Public methodColumnsReturns an array that contains the specified WebGridColumn instances.
Public methodEquals (Inherited from Object.)
Protected methodFinalize (Inherited from Object.)
Public methodGetContainerUpdateScriptReturns a JavaScript statement that can be used to update the HTML element that is associated with the WebGrid instance on the specified web page.
Public methodGetHashCode (Inherited from Object.)
Public methodGetHtmlReturns the HTML markup that is used to render the WebGrid instance and using the specified paging options.
Public methodGetPageUrlReturns a URL that can be used to display the specified data page of the WebGrid instance.
Public methodGetSortUrlReturns a URL that can be used to sort the WebGrid instance by the specified column.
Public methodGetType (Inherited from Object.)
Protected methodMemberwiseClone (Inherited from Object.)
Public methodPagerReturns the HTML markup that is used to provide the specified paging support for the WebGrid instance.
Public methodTableReturns the HTML markup that is used to render the WebGrid instance.
Public methodToString (Inherited from Object.)
Top

This class represents a helper, which is a component that simplifies web programming in ASP.NET Web Pages. You can use the WebGrid class to organize and display data on a web page by using an HTML table element.

The following example shows how to create and populate a WebGrid instance.


@{  
    var db = Database.Open("SmallBakery"); 
    var selectQueryString = "SELECT * FROM Product ORDER BY Id"; 
    var data = db.Query(selectQueryString); 
    var grid = new WebGrid(source: data, 
                           defaultSort: "Name",  
                           rowsPerPage: 3); 
    grid.SortDirection = SortDirection.Ascending;
}
<!DOCTYPE html> 
<html> 
    <head> 
        <title>Displaying Data Using the WebGrid Helper (with Paging)</title> 
        <style type="text/css"> 
            .grid { margin: 4px; border-collapse: collapse; width: 600px; } 
            .head { background-color: #E8E8E8; font-weight: bold; color: #FFF; } 
            .grid th, .grid td { border: 1px solid #C0C0C0; padding: 5px; } 
            .alt { background-color: #E8E8E8; color: #000; } 
            .product { width: 200px; font-weight:bold;} 
        </style> 
    </head> 
    <body> 
        <h1>Small Bakery Products</h1> 
        <div id="grid"> 
            @grid.GetHtml( 
                tableStyle: "grid", 
                headerStyle: "head", 
                alternatingRowStyle: "alt", 
                columns: grid.Columns( 
                    grid.Column("Name", "Product", style: "product"), 
                    grid.Column("Description", format:@<i>@item.Description</i>), 
                    grid.Column("Price", format:@<text>$@item.Price</text>) 
                ) 
            ) 
        </div> 
    </body> 
</html>


Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.
Show:
© 2014 Microsoft