This is an all-in-one callback gridview. All gridview actions: sorting, paging or searching are performed using ASP callbacks.
This grid includes 4 helpful features:
- Page size updating
- Column sorting
- Quick search/ filtering
I really needed an ASP.NET based
gridview to execute all its commands using callbacks. After a couple of attempts, I have finally created a RTM version of the code. All actions from paging through to filtering can callback commands. (so there is no need for any nasty page postbacks).
Using the Code
Let's start off with the main
The grid consists of 5 major events. These events are used to call and manipulate your datasource. The events being:
OnGridLoadData: Is the first event that is called when the
GridView requires a datasource, i.e., when your
gridview is required to display data for the first time.
OnGridViewPaging: Allows for the paging of multiple rows of your datasource
OnGridViewSorting: Allows for the ordering of your datasource
OnGridViewFiltering: Allows for the "quick filtering" of your datasource
OnGridViewPageSizing: Allows for the updating of this visible page size (i.e., number of rows per page)
Next, you will want to have data columns within your
<HPS:HPLabelField HeaderText="Name" DataField="Name"
<HPS:HPLabelField HeaderText="Vote Count"
<HPS:HPLabelField HeaderText="Date added"
There are a few different column templates at your disposal in the
gridview, but you will use the
HPLabelField most of the time to display your data. There are a few properties to keep in mind:
DataField - This will define what this column will bind to in relation to your datasource.
HeaderText - This will define what text will be displayed at the top of your column.
AllowQuickSearch - This will define whether or not you want this column to be included within the "quick search" feature. More on this later.
FilterExpression- This will define what your column will filter (search) by in relation to your datasource.
SortExpression- This will define what your column will order by in relation to your datasource.
All callback events require that the developer assigns a
datasource to the
gridview. This first example shows how we can simply assign a List of objects to the
gridview. NOTE: Your columns
DataField MUST be correctly assigned to a property within your binding object source. Example: If you set your column's
datafield to "
Name", then this column must correspond to a property called "
Name" within your
protected void grdView_GridLoadData(object sender, HollowPoint.UI.WebControls.GridViewPageLoadEventArgs e)
var data = GetData();
grdView.DataSource = data;
Loads a List of objects and assigns the LIST to the
DataSource property of the
int counter = 0;
if (int.TryParse(e.FilterExpression, out counter))
data = GetData().Where(t => t.VoteCount == counter ||
data = GetData().Where(t => t.Name.ToLower().Contains(e.FilterExpression.ToLower())).ToList();
grdView.DataSource = data;
Here, we will pass the "filter text" on to the "
Search" method. This will inform the
gridview UI that a search is being performed and that it will need to highlight the required text. Now it is up to the developer to define how the filtering will be executed. As you see above, I retrieve the required datasource and then I perform a "
Where" LINQ operation on the LIST based on the filter text that I want to search by. This "filtered" datasource that is returned to the
gridview will now only contain items that passed the LINQ expressions requirements.
Hoping to get some feedback on this control. If people have any suggestions, I will do my best to try and include them into the project. Watch this space.