Table of Contents
- Getting Started
- EO.Pdf
- EO.Web
- Overview
- Installation & Deployement
- EO.Web ToolTip
- EO.Web Rating
- EO.Web Slider & RangeSlider
- EO.Web ListBox
- EO.Web ComboBox
- EO.Web Captcha
- EO.Web ASPX To PDF
- EO.Web Slide
- EO.Web Flyout
- EO.Web EditableLabel
- EO.Web ImageZoom
- EO.Web Floater
- EO.Web Downloader
- EO.Web ColorPicker
- EO.Web HTML Editor
- EO.Web File Explorer
- EO.Web SpellChecker
- EO.Web Grid
- EO.Web MaskedEdit
- EO.Web Splitter
- EO.Web Menu
- EO.Web Slide Menu
- EO.Web TabStrip
- EO.Web TreeView
- EO.Web Calendar
- EO.Web Callback
- EO.Web MultiPage
- EO.Web Dialog
- EO.Web AJAXUploader
- EO.Web ProgressBar - Free!
- EO.Web ToolBar - Free!
- EO.WebBrowser
- EO.Wpf
- Common Topics
- Reference
Populating the Grid |
A Grid is almost always populated from a data source. To populate from a data source, you should set the Grid's DataSource and then call DataBind.
EO.Web supports the following type of data source object through DataSource property:
Data Source | Remarks |
---|---|
DataView | One GridColumn is created based on each row. Each GridColumn's DataField are used to evaluate values for each cell. |
DataTable | The DefaultView of the DataTable is actually used to populate the grid. |
IDataReader | Similar to DataView, each row is used to create a GridItem. |
DataSet | Grid.DataTable property is used locate the DataTable object that is to be used for populating the grid. |
IEnumerable | Each element of the enumerable will be used to create a GridItem. DataField is used as property name in this case. For example, the IEnumerable object can be an array of Point structure, while the Grid contains two columns with their DataField set to "X" and "Y" respectively. |
private void Populate() { using (DemoDB db = new DemoDB()) { string sql = "SELECT * FROM Topics"; Grid1.DataSource = db.ExecuteReader(sql); Grid1.DataBind(); } }
The above code populates the Grid based on the entire source data, which can be unworkable if there are too many records. In that case, you should enable paging. When paging is enabled, you will need to first set the total number of records, then populate only the current page.
private void Page_Load(object sender, EventArgs e) { if (!Page.IsPostBack) { SetRecordCount(); Populate(); } }
The following code demonstrates how to set the total number of records through RecordCount property:
private void SetRecordCount() { using (DemoDB db = new DemoDB()) { string sql = "SELECT COUNT(*) FROM Topics"; int nRecordCount = (int)db.ExecuteScalar(sql); Grid1.RecordCount = nRecordCount; } }
The following code demonstrates how to populate the current page:
private void Populate() { using (DemoDB db = new DemoDB()) { string sql1 = string.Format( "SELECT TOP {0} * FROM Topics ORDER BY PostedBy ASC", (Grid1.CurrentPage + 1) * Grid1.PageSize); string sql2 = string.Format( "SELECT TOP {0} * FROM ({1}) ORDER BY PostedBy DESC", Grid1.PageSize, sql1); OleDbDataReader reader = db.ExecuteReader(sql2); Grid1.DataSource = reader; Grid1.DataBind(); } }