Infragistics ASPNETGrid Cheat Sheet
Infragistics ASPNETGrid Cheat Sheet
Notes
An instance of the ScriptManager component is required in all instances.
This cheat sheet is an excellent resource for UltraWebGrid customers looking to move to the WebDataGrid or WebHiearchicalDataGrid controls.
The notation of ‘Same’ for WebHierarchicalDataGrid implementations does not necessarily indicate that the required code is exactly the same. You may
have to access the grid slightly differently, but generally the approach is the same.
The following code snippets demonstrate how to explicitly add the ColumnMoving behavior a child band, although you may add any grid behavior using this
approach.
In the Designer
In ASPX
<Bands>
<ig:Band ...>
<Columns>
...
</Columns>
<Behaviors>
<ig:ColumnMoving />
</Behaviors>
</ig:Band>
</Bands>
In Code Behind
using Infragistics.Web.UI.GridControls;
...
protected void WebHierarchicalDataGrid1_InitializeBand(object sender, BandEventArgs e)
{
e.Band.Behaviors.Add(new ColumnMoving());
}
activation.set_activeCell(cCell);
}
}
}
return activation.get_activeCell();
}
if (childGrid != null) {
activeCell = activation.get_activeCell();
}
}
return activeCell;
}
More Info
WebHierarchicalDataGrid Activation
Ajax: Events
WebDataGrid WebHierarchicalDataGrid
Not Implemented Note: See Automatic Load on Demand section for basic settings.
When the grid’s EnableAjax property is set to True (default value), data
interactions are asynchronous. If the property is set to False, data interactions
result in a full page postback.
Not Implemented Achieving Load on Demand requires you to first bind to the top-level data
source in Page_Load, and then the child-level data on during
RowIslandsPopulating event.
Note: The grid must have the EnableAjax property set to True for the
Not Implemented Set the InitialDataBindDepth property to the data levels desired during
initial load. The default is 0 which only loads the root data. A value of -1
disables load on demand and loads all data levels.
Note: See the Ajax: Load on Demand (Automatic) section for Ajax interactions
1. Configure Column Settings for hidden column Same for parent grid
1.1. Open the Smart Tag and select Edit Columns
1.2. Choose a column from Selected Fields To add behavior to child bands, see: Adding Behaviors to
1.3. Set: Hidden = True WebHierarchicalDataGrid Child Bands.
Columns: Moving
WebDataGrid WebHierarchicalDataGrid
More Info
WebDataGrid Column Moving
2. Further configure the Column Fixing Behavior in the dialog window (if
necessary)
Columns: Resizing
WebDataGrid WebHierarchicalDataGrid
1. Create an UnboundField Approach for the WebHierarchicalDataGrid is generally the same, although
1.1. Open the Smart Tag configuring for child bands requires you to add settings and apply the logic in
1.2. Select Edit Columns scope of a child band.
1.3. Select UnboundField
1.4. Click the Add Field button
1.5. Select the new field in the Selected Fields list
1.5.1. Set DataFormatString to {0:c2} (your value will vary depending
on needs)
1.5.2.Set DataType to System.Decimal (your value will vary depending
on needs)
1.5.3.Set the Key field to a unique value
1.5.4.Set Header -> Text to the desired header text
1.6. Close the dialog
2. Implement the field’s logic in the RowInitialized event
2.1. In the grid’s Properties window, switch to the Events view
Copyright © 2003-2013 Infragistics, Inc. All rights reserved. Version 13.2.02
2.2. Double-click on the RowInitialized event
2.3. Implement the logic for your unbound field in the RowInitialized
event handler
In ASPX
<Columns>
...
<ig:UnboundField
Key="TotalRetail"
DataType="System.Decimal"
DataFormatString="{0:c2}">
<Header Text="Total Retail" />
</ig:UnboundField>
</Columns>
In Code Behind
Execute in InitializeRow event handler
using Infragistics.Web.UI.GridControls;
...
GridRecordItem unbound;
GridRecordItem bound1;
GridRecordItem bound2;
int indexOfUnbound = 4;
int indexOfBound1 = 3;
int indexOfBound2 = 2;
unbound = e.Row.Items[indexOfUnbound];
bound1 = e.Row.Items[indexOfBound1];
bound2 = e.Row.Items[indexOfBound2];
e.Row.Items[indexOfUnbound].Value = total;
Binding to a boolean field in the grid will create a BoundCheckboxField by Approach for the WebHierarchicalDataGrid is generally the same, although
default as the column type. configuring for child bands requires you to add settings and assign the
converter in scope of a child band.
Additionally, you may display any bound data as a checkbox field by
implementing the IBooleanConverter interface.
In Code Behind
public partial class WDG : System.Web.UI.Page
{
private int UNIT_PRICE_COLUMN_INDEX = 0;
Note: Your implementation will likely require support for other data
types beyond a decimal type.
CRUD: Auto
WebDataGrid WebHierarchicalDataGrid
CRUD actions for the grid are batched, therefore once your set up Auto CRUD Same for parent grid
you still need to add a control to the page to send change message back to the
server. To add behavior to child bands, see: Adding Behaviors to
WebHierarchicalDataGrid Child Bands.
1. Setup the data source
1.1. Bind the grid to a data source control that implements functionality
for inserting, selecting, updating and deleting
2. Set the DataKeyFields property
2.1. From the Properties window set the DataKeyFields property the field
name of the primary key value(s)
3. Enable editing behaviors
3.1. Open the Smart Tag
3.2. Select Edit Behaviors
3.3. Check Selection
3.3.1.Set RowSelectType equal to Single
3.4. Check Row Selectors
3.5. Check Editing Core
3.5.1.Ensure AutoCRUD is equal to True
3.6. Check Cell Editing
3.7. Check Row Adding
3.8. Check Row Deleting
3.9. Click OK
4. Add Control to Cause Postback
4.1. Add a control like a server Button to initiate postback to the server
Copyright © 2003-2013 Infragistics, Inc. All rights reserved. Version 13.2.02
More Info
WebDataGrid Auto CRUD (video)
CRUD: Manual
WebDataGrid WebHierarchicalDataGrid
1. Configure grid for manual CRUD operations Same for parent grid
1.1. From the Properties window set the DataKeyFields property the field
name of the primary key value(s) To add behavior to child bands, see: Adding Behaviors to
1.2. Set the EnableAjax property equal to False WebHierarchicalDataGrid Child Bands.
2. Enable CRUD behaviors
2.1. Open the Smart Tag
2.2. Select Edit Behaviors
2.3. Check Selection
2.4. Check Row Selection
2.5. Check Activation
2.6. Check Editing Core
2.6.1.Ensure AutoCRUD is set to False
2.7. Check Cell Editing
2.7.1.Set EditModeActions -> EnableOnKeyPress equal to True
2.8. Check Row Adding
2.8.1.Set EditModeActions -> EnableOnKeyPress equal to True
2.9. Check Row Deleting
3. Subscribe to CRUD events
3.1. From the Properties window, double click on these events to create
event handlers:
3.1.1.EditingCore.RowAdding
3.1.2. EditingCore.RowDeleting
3.1.3. EditingCore.RowUpdating
using Infragistics.Web.UI.GridControls;
…
public void BindData()
{
this.wdg.Rows.Clear();
this.wdg.DataSource = this.GetData();
this.wdg.DataBind();
}
this.Repository.Insert(person);
this.BindData();
}
this.Repository.Update(person);
this.BindData();
}
DataBinding: HeirachicalDataSource
WebDataGrid WebHierarchicalDataGrid
Not Implemented The WebHierarchicalDataSource control acts as a wrapper and connector for
Copyright © 2003-2013 Infragistics, Inc. All rights reserved. Version 13.2.02
two or more data source controls that correlate together via related fields.
The following procedure describes how to add two data sources as child views
to the WebHierarchicalDataSource control.
DataBinding: DataSet
WebDataGrid WebHierarchicalDataGrid
To bind a DataSet to the WebDataGrid, set the DataSource property equal to a Same
DataSet and then call DataBind on the grid.
In Code Behind
protected void Page_Load(object sender, EventArgs e)
{
ProductRepository repository = new ProductRepository();
DataSet ds = repository.GetAllDataSet();
this.WebDataGrid1.DataSource = ds;
this.WebDataGrid1.DataBind();
}
To bind a DataTable to the WebDataGrid, set the DataSource property equal to a Same
DataTable and then call DataBind on the grid.
In Code Behind
protected void Page_Load(object sender, EventArgs e)
{
ProductRepository repository = new ProductRepository();
DataTable ds = repository.GetAllDataTable();
this.WebDataGrid1.DataSource = ds;
this.WebDataGrid1.DataBind();
}
DataBinding: IEnumerable
WebDataGrid WebHierarchicalDataGrid
In Code Behind
protected void Page_Load(object sender, EventArgs e)
{
ProductRepository repository = new ProductRepository();
IEnumerable<Product> data = repository.GetAllEnumerable();
this.WebDataGrid1.DataSource = data;
this.WebDataGrid1.DataBind();
}
DataBinding: AccessDataSource
WebDataGrid WebHierarchicalDataGrid
1. Add a AccessDataSource control to the page Follow the procedure as described in DataBinding: HierarchicalDataSource and
1.1. Drag a AccessDataSource control to the design surface select AccessDataSource as the data source type for steps 3.2.1 and/or 4.3.1.
1.2. Open the Properties window and give the control a value for the Id
property
Copyright © 2003-2013 Infragistics, Inc. All rights reserved. Version 13.2.02
1.3. Open the data source’s Smart Tag
1.4. Follow the wizard to complete configuration of the data source
control
2. Associate the data source control to the grid
2.1. Open the grid’s Smart Tag
2.2. Click on the drop down next to the label Choose Data Source
2.3. Select the data source ID as defined in step 1.2
Note: You may see a dialog box asking you if you want to regenerate
the column and key settings for the grid. If you are setting up the grid
for the first time then you may safely click Yes. If you are unsure, you
may want to click No and manually configure the column and key
options.
DataBinding: SqlDataSource
WebDataGrid WebHierarchicalDataGrid
1. Add a SqlDataSource control to the page Follow the procedure as described in DataBinding: HierarchicalDataSource and
1.1. Drag a SqlDataSource control to the design surface select SqlDataSource as the data source type for steps 3.2.1 and/or 4.3.1.
1.2. Open the Properties window and give the control a value for the Id
property
1.3. Open the data source’s Smart Tag
1.4. Follow the wizard to complete configuration of the data source
control
2. Associate the data source control to the grid
2.1. Open the grid’s Smart Tag
2.2. Click on the drop down next to the label Choose Data Source
2.3. Select the data source ID as defined in step 1.2
Note: You may see a dialog box asking you if you want to regenerate
the column and key settings for the grid. If you are setting up the grid
for the first time then you may safely click Yes. If you are unsure, you
may want to click No and manually configure the column and key
options.
1. Add a ObjectDataSource control to the page Follow the procedure as described in DataBinding: Hierarchical Data and
1.1. Drag a ObjectDataSource control to the design surface select ObjectDataSource as the data source type for steps 3.2.1 and/or 4.3.1.
1.2. Open the Properties window and give the control a value for the Id
property
1.3. Open the data source’s Smart Tag
1.4. Follow the wizard to complete configuration of the data source
control
2. Associate the data source control to the grid
2.1. Open the grid’s Smart Tag
2.2. Click on the drop down next to the label Choose Data Source
2.3. Select the data source ID as defined in step 1.2
Note: You may see a dialog box asking you if you want to regenerate
the column and key settings for the grid. If you are setting up the grid
for the first time then you may safely click Yes. If you are unsure, you
may want to click No and manually configure the column and key
options.
DataBinding: LinqDataSource
WebDataGrid WebHierarchicalDataGrid
1. Add a LinqDataSource control to the page Follow the procedure as described in DataBinding: Hierarchical Data and
1.1. Drag a LinqDataSource control to the design surface select LinqDataSource as the data source type for steps 3.2.1 and/or 4.3.1.
1.2. Open the Properties window and give the control a value for the Id
property
1.3. Open the data source’s Smart Tag
1.4. Follow the wizard to complete configuration of the data source
control
2. Associate the data source control to the grid
2.1. Open the grid’s Smart Tag
2.2. Click on the drop down next to the label Choose Data Source
2.3. Select the data source ID as defined in step 1.2
Copyright © 2003-2013 Infragistics, Inc. All rights reserved. Version 13.2.02
Note: You may see a dialog box asking you if you want to regenerate
the column and key settings for the grid. If you are setting up the grid
for the first time then you may safely click Yes. If you are unsure, you
may want to click No and manually configure the column and key
options.
// Fill array with all values to insert into the row var topRowIsland = grid.get_gridView();
var values = ["10000", "New Product"]; var cellValues = ["1", "Bob", "Green", "1/2/1983"];
topRowIsland.get_rows().add(cellValues);
grid.get_rows().add(values);
}
Child Level
var grid = $find("WebHierarchicalDataGrid1");
On the Server
To add rows to the grid on the server, add the data to your data source and re- var childGrid = topRowIsland.get_rows().get_row(3).get_rowIslands()[0];
bind the grid. cellValues = ["1", "25 Main Road", "New York", "NY", "19234"];
childGrid.get_rows().add(cellValues);
1. Add the Row Deleting behavior 1. Add the Row Deleting behavior
1.1. Open the Smart Tag 1.1. Open the Smart Tag
1.2. Click Edit Behaviors 1.2. Click Edit Behaviors
1.3. Check Selection 1.3. Check Selection
1.4. Check Editing Core 1.4. Check Editing Core
1.5. Check Row Deleting 1.5. Check Row Deleting
Once the deleting behavior is added to the grid then you may remove rows Once the deleting behavior is added to the grid then you may remove rows
from the grid a number of different ways. from the grid a number of different ways.
Note: If the data source attached to the grid is not automatically Note: If the data source attached to the grid is not automatically
updated by the grid then you must handle the update events manually updated by the grid then you must handle the update events manually
to make changes on the server. to make changes on the server.
grid.get_rows().remove(row);
Export to Excel
WebDataGrid WebHierarchicalDataGrid
In Code Behind
Execute in the btnExport_Click event handler
// file will get extension based upon workbook format
this.eExporter.DownloadName = "data";
eExporter.WorkbookFormat =
Infragistics.Documents.Excel.WorkbookFormat.Excel2007;
Export to PDF
WebDataGrid WebHierarchicalDataGrid
In Code Behind
Execute in the btnExport_Click event handler
this.dExporter.DownloadName = "data.pdf";
dExporter.Format = Infragistics.Web.UI.GridControls.FileFormat.PDF;
dExporter.TargetPaperOrientation = Infragistics.
Documents.
Report.
PageOrientation.
dExporter.Margins = PageMargins.Normal;
dExporter.TargetPaperSize = PageSizes.A4;
Filtering
WebDataGrid WebHierarchicalDataGrid
1. Add the Row Deleting behavior 1. Add the Row Deleting behavior
1.1. Open the Smart Tag 1.1. Open the Smart Tag
1.2. Click Edit Behaviors 1.2. Click Edit Behaviors
1.3. Check Filtering 1.3. Check Filtering
1.3.1.Set EnableInheritance equal to True
Once the Filtering behavior is enabled on the grid the user may filter columns
based on a number of different criteria: Once the Filtering behavior is enabled on the grid the user may filter columns
based on a number of different criteria:
By default the Filtering behavior is enabled for all columns with blank filter
rules. The following snippets demonstrate how to programmatically customize By default the Filtering behavior is enabled for all columns with blank filter
the filter settings. rules. The following snippets demonstrate how to programmatically customize
the filter settings.
Row Numbering
WebDataGrid WebHierarchicalDataGrid
Row Summaries
WebDataGrid WebHierarchicalDataGrid
Selection: Cells
WebDataGrid WebHierarchicalDataGrid
Select a Cell
var grid = $find('<%= WebHierarchicalDataGrid1.ClientID %>');
var parentGrid = grid.get_gridView();
var childGrid = grid.get_gridView().
get_rows().
get_row(0).
get_rowIslands(0)[0];
if (parentGrid != null) {
var cell = parentGrid.get_rows().
get_row(0).
get_cell(0);
parentGrid.get_behaviors().
get_selection().
childGrid.get_behaviors().
get_selection().
get_selectedCells().
add(cell);
}
Selection: Columns
WebDataGrid WebHierarchicalDataGrid
Once selection is enabled on the grid then you may select columns on the Once selection is enabled on the grid then you may select columns on the
server or client. server or client.
Select a Column
var grid = $find('<%= WebHierarchicalDataGrid1.ClientID %>');
var parentGrid = grid.get_gridView();
var childGrid = grid.get_gridView().
get_rows().
get_row(3).
get_rowIslands(0)[0];
var column;
Selection: Rows
WebDataGrid WebHierarchicalDataGrid
Once selection is enabled on the grid then you may select rows on the server Once selection is enabled on the grid then you may select rows on the server
or client. or client.
Select a Row
var grid = $find('<%= WebHierarchicalDataGrid1.ClientID %>');
var parentGrid = grid.get_gridView();
var childGrid = grid.get_gridView().
get_rows().
get_row(3).
get_rowIslands(0)[0];
var row;
<Columns>
<ig:TemplateDataField Key="Template1">
<ItemTemplate>
<asp:Button id="btnSelect" Text="Select" runat="server" />
<%# DataBinder.Eval(
((Infragistics.Web.UI.TemplateContainer)Container).
DataItem,
"ProductName") %>
</ItemTemplate>
</ig:TemplateDataField>
</Columns>
Note: When you are finished configuring the template in Design view click End
Template Editing on the Smart Tag to return to the default Designer view of
the grid.
container.Controls.Add(label1);
}
}
Grid Events
WebDataGrid WebHierarchicalDataGrid Events Args
X ContainerGridDataBinding DataBindingEventArgs
X CustomDataBinding DataBindingEventArgs
X X DataBinding EventArgs
X X DataBound EventArgs
X X Disposed EventArgs
X GroupedColumnsChanged GroupedColumnsChangedEventArgs
X GroupedColumnsChanging GroupedColumnsChangingEventArgs
X GroupedRowInitialized GroupedRowEventArgs
X X HeaderCheckBoxClicked HeaderCheckBoxEventArgs
X X Init EventArgs
X InitializeBand BandEventArgs
X X InitializeRow RowEventArgs
X X ItemCommand HandleCommandEventArgs
X X Load EventArgs
X X PreRender EventArgs
X RowCollapsed ContainerRowEventArgs
X RowExpanded ContainerRowEventArgs
X RowIslandsCreated RowIslandEventArgs
X RowIslandsDataBinding RowIslandEventArgs
X RowIslandsDataBound RowIslandEventArgs
Copyright © 2003-2013 Infragistics, Inc. All rights reserved. Version 13.2.02
X RowIslandsPopulated ContainerRowEventArgs
X RowIslandsPopulating ContainerRowCancelEventArgs
X X Unload EventArgs
Events by Behavior
As the WebHierarchicalDataGrid extends the WebDataGrid, some events share event arg classes.
Arg Arg
Behavior Client Events (Args)
Links Server Events (Args) Links
Initialize None
Copied
Copying
Cut
Clipboard None None
Cutting
Initialize
Pasted
Initialize None
Initialize None
FilterDropdownDisplayed
FilterDropdownDisplaying
FilterDropDownHidden None
FilterDropDownHiding
Initialize
Initialize None
None
PageIndexChanging (PagerEventArgs) WDG
Paging
WHDG
Row
None Uses Editing Core events
Deleting
Initialize None
Row None
TemplateClosing (CancelEditRowEventArgs) WDG
Editing WHDG
Template
TemplateOpened (EditRowEventArgs) WDG
WHDG
WDG
RowSelectionChanging (RowSelectionChangingEventArgs) WHDG
Initialize None
Virtual
None
Scrolling MoreRowsReceived (MoreRowsRecievedEventArgs) Same
Revision History
07/08/2011:
o Added snippet sections:
Ajax: Load on Demand (Manual)
Editing: Adding Rows
Column: Summaries
o Added tables:
Grid Events
Events by Behavior