New to Telerik UI for ASP.NET AJAX? Start a free 30-day trial

Class that represents the rows of each GridTableView with RadGrid. All Items in RadGrid inherit from this class. RadGrid creates the items runtime, when it binds to data.

Definition

Namespace:Telerik.Web.UI

Assembly:Telerik.Web.UI.dll

Syntax:

C#
public abstract class GridItem : GridTableRow, IComponent, IDisposable, IParserAccessor, IUrlResolutionService, IDataBindingsAccessor, IControlBuilderAccessor, IControlDesignerAccessor, IExpressionsAccessor, IAttributeAccessor, INamingContainer

Inheritance: objectControlWebControlTableRowGridTableRowGridItem...

Derived Classes: GridCommandItemGridDetailTemplateItemGridEditableItemGridFilteringItemGridFooterItemGridGroupFooterItemGridGroupHeaderItemGridGroupPanelItemGridHeaderItemGridMultiRowItemGridNestedViewItemGridNoRecordsItemGridPagerItemGridStatusBarItem...

Implements: IAttributeAccessorIComponentIControlBuilderAccessorIControlDesignerAccessorIDataBindingsAccessorIDisposableIExpressionsAccessorINamingContainerIParserAccessorIUrlResolutionService...

Inherited Members GridTableRow.OriginalClientIDGridTableRow.ClientIDTableRow.CreateControlStyle()TableRow.CreateControlCollection()TableRow.CellsTableRow.HorizontalAlignTableRow.SupportsDisabledAttributeTableRow.TableSectionTableRow.VerticalAlignWebControl.ApplyStyle(Style)WebControl.CopyBaseAttributes(WebControl)WebControl.TrackViewState()WebControl.MergeStyle(Style)WebControl.Render(HtmlTextWriter)WebControl.RenderBeginTag(HtmlTextWriter)WebControl.RenderEndTag(HtmlTextWriter)WebControl.RenderContents(HtmlTextWriter)WebControl.SaveViewState()WebControl.AccessKeyWebControl.AttributesWebControl.BackColorWebControl.BorderColorWebControl.BorderWidthWebControl.BorderStyleWebControl.ControlStyleWebControl.ControlStyleCreatedWebControl.CssClassWebControl.DisabledCssClassWebControl.StyleWebControl.EnabledWebControl.EnableThemingWebControl.FontWebControl.ForeColorWebControl.HasAttributesWebControl.HeightWebControl.IsEnabledWebControl.SkinIDWebControl.TabIndexWebControl.TagKeyWebControl.TagNameWebControl.ToolTipWebControl.WidthControl.ResolveAdapter()Control.HasEvents()Control.GetRouteUrl(object)Control.GetRouteUrl(string, object)Control.GetRouteUrl(RouteValueDictionary)Control.GetRouteUrl(string, RouteValueDictionary)Control.GetUniqueIDRelativeTo(Control)Control.ApplyStyleSheetSkin(Page)Control.OnDataBinding(EventArgs)Control.DataBind()Control.DataBind(bool)Control.DataBindChildren()Control.AddParsedSubObject(object)Control.EnsureID()Control.OnInit(EventArgs)Control.ClearChildState()Control.ClearChildControlState()Control.ClearChildViewState()Control.ClearEffectiveClientIDMode()Control.ClearCachedClientID()Control.Focus()Control.LoadControlState(object)Control.MapPathSecure(string)Control.OpenFile(string)Control.OnLoad(EventArgs)Control.OnPreRender(EventArgs)Control.BuildProfileTree(string, bool)Control.SaveControlState()Control.RenderChildren(HtmlTextWriter)Control.RenderControl(HtmlTextWriter)Control.RenderControl(HtmlTextWriter, ControlAdapter)Control.OnUnload(EventArgs)Control.Dispose()Control.RaiseBubbleEvent(object, EventArgs)Control.AddedControl(Control, int)Control.CreateChildControls()Control.ResolveUrl(string)Control.ResolveClientUrl(string)Control.FindControl(string)Control.FindControl(string, int)Control.GetDesignModeState()Control.HasControls()Control.IsLiteralContent()Control.EnsureChildControls()Control.RemovedControl(Control)Control.SetDesignModeState(IDictionary)Control.SetRenderMethodDelegate(RenderMethod)Control.ClientIDModeControl.ClientIDSeparatorControl.ContextControl.AdapterControl.DesignModeControl.EventsControl.IDControl.IsChildControlStateClearedControl.EnableViewStateControl.ViewStateModeControl.IsViewStateEnabledControl.NamingContainerControl.IdSeparatorControl.LoadViewStateByIDControl.PageControl.RenderingCompatibilityControl.TemplateControlControl.ParentControl.TemplateSourceDirectoryControl.AppRelativeTemplateSourceDirectoryControl.SiteControl.VisibleControl.UniqueIDControl.HasChildViewStateControl.ControlsControl.ValidateRequestModeControl.ViewStateControl.ViewStateIgnoresCaseControl.ChildControlsCreatedControl.IsTrackingViewStateControl.DisposedControl.DataBindingControl.InitControl.LoadControl.PreRenderControl.Unloadobject.ToString()object.Equals(object)object.Equals(object, object)object.ReferenceEquals(object, object)object.GetHashCode()object.GetType()object.MemberwiseClone()...

Constructors

Initializes the base properties of an item.

C#
public GridItem(GridTableView ownerTableView, int itemIndex, int dataSetIndex, GridItemType itemType)
Parameters:ownerTableViewGridTableViewitemIndexintdataSetIndexintitemTypeGridItemType

Properties

Gets a value indicating whether the item can be "expanded" to show its child items

C#
public virtual bool CanExpand { get; }
Example:
cs-api-definition
protected void RadGrid1_ItemCreated(object sender, GridItemEventArgs e)
{
if (e.Item is GridItem && (e.Item as GridItem).CanExpand == true)
{
Label1.Text = "Item was expanded";
}
}

The original DataItem from the DataSource. See examples section below.

C#
public virtual object DataItem { get; set; }
Example:
C#
For example if you bind the grid to a <strong>DataView</strong> object the
<strong>DataItem</strong> will represent the <strong>DataRowView</strong> object
extracted from the <strong>DataView</strong> for this <strong>GridItem</strong>. Note
that the <strong>DataItem</strong> object is available only when grid binds to data
(inside the <strong>ItemDataBound</strong> server event handler).

Gets the index of the GridDataItem in the underlying DataTable/specified table from a DataSet.

C#
public virtual int DataSetIndex { get; }
Property Value:

Integer

Sets whether the GridItem will be visible or with style="display:none;"

C#
public virtual bool Display { get; set; }
Example:
cs-api-definition
if (e.Item is GridCommandItem)
{
e.Item.Display = false;
}

Sets the Item in edit mode. Requires Telerik RadGrid to rebind.

C#
public virtual bool Edit { get; set; }

If EditMode is set to InPlace, the grid column editors will be displayed inline of this item.

If EditMode is set to EditForms, a new GridItem will be created, which will be child of this item (GridEditFormItem). The new item will hold the edit form.

Example:
C#
<p>We suggest using IsInEditMode instead of Edit to check whether an Item is in
edit more or not.</p>

Gets or sets a value indicating whether the grid item is expanded or collapsed.

C#
public virtual bool Expanded { get; set; }
Example:
cs-api-definition
for(int i = 0; i &lt; RadGrid.Items.Count - 1;i++)
if(RadGrid.Items[i].Expanded)
{
RadGrid.Items[i].Expanded = false;
}

Gets the index of the Item in the group. This works only when grouping.

C#
public string GroupIndex { get; }
Property Value:

Returns a string formed: X_Y_Z, where:
- X is a zero-based value representing the group index (the first group of results will have index = 0)

- Y is a zero-based value representing the group level. If you group the grid using 2 criteria, the inner groups will have index = 1.

- Z is a zero-based value representing the GridItem index in the group (the first item will have index = 0)

Note that if you use more criteria, you will have more indexes returned: X_Y_Z_W, where the last one is always the item index in the group.

Example:
cs-api-definition
if (e.Item.GroupIndex == EditItemGroupIndex | EditItemGroupIndex.StartsWith(e.Item.GroupIndex + "_"))
{
e.Item.Expanded = true;
}

Gets a value indicating whether this item has child items - or items somehow related to this.

C#
public virtual bool HasChildItems { get; }
Example:
cs-api-definition
protected void RadGrid1_ItemCreated(object sender, GridItemEventArgs e)
{
if (e.Item is GridItem &amp;&amp; (e.Item as GridItem).HasChildItems == true)
{
Label1.Text = "has items";
}
}

Gets a value indicating whether the grid item is bound to a data source.

C#
public virtual bool IsDataBound { get; }
Example:
C#
Default value is true when the grid is databound.

Gets a value indicating whether the grid item is in edit mode at the moment.

C#
public virtual bool IsInEditMode { get; }
Example:
cs-api-definition
if (e.Item is GridEditableItem &amp;&amp; e.Item.IsInEditMode)
{
TextBox txt = (e.Item as GridEditableItem)["SomeColumnName"].Controls[0] as TextBox;
}

Gets the index of the grid item among the Items collection. This index also can be used to get the DataKeyValues corresponding to this item from a GridTableView.

C#
public virtual int ItemIndex { get; }
Example:
C#
Gets a value representing the index of this item among the
<xref href="Telerik.Web.UI.GridTableView.Items" data-throw-if-not-resolved="false"></xref> collection. This index also can be used to
get the <strong>DataKeyValues</strong> corresponding to this item from a
<strong>GridTableView.</strong>

Get the unique item index among all the item in the hierarchy. This index is used when setting item to selected, edited, etc

C#
public string ItemIndexHierarchical { get; }
Example:
cs-api-definition
protected void RadGrid1_SelectedIndexChanged(object sender, EventArgs e)
{
Response.Write(RadGrid1.SelectedItems[0].ItemIndexHierarchical);
}

Gets the respective GridItemType of the grid item.

C#
public virtual GridItemType ItemType { get; }
Example:
cs-api-definition
foreach (GridDataItem dataItem in rgdStateRules.MasterTableView.Items)
{
if (dataItem.ItemType == GridItemType.Item ||
dataItem.ItemType ==   GridItemType.AlternatingItem)
{
string reqName = dataItem["SomeColumnUniqueName"]. Text;
....
}
}

Gets the ClientID of the RadGrid instance that owns the item.

C#
[Browsable(false)]
public virtual string OwnerGridID { get; }

This would be useful if several controls use the same eventhandler and you need to diferentiate the Grid instances in the handler.

Example:
cs-api-definition
protected void RadGrid1_ItemCreated(object sender, GridItemEventArgs e)
{
if (e.Item is GridEditableItem &amp;&amp; e.Item.IsInEditMode)
{
Response.Write(e.Item.OwnerGridID);

}
}

Gets the ClientID of the GridTableView that owns this instance.

C#
[Browsable(false)]
public virtual string OwnerID { get; }
Example:
cs-api-definition
protected void RadGrid1_SelectedIndexChanged(object sender, EventArgs e)
{
Label1.Text = RadGrid1.SelectedItems[0].OwnerID;
}

Gets a reference to the GridTableView that owns this GridItem.

C#
public GridTableView OwnerTableView { get; }
Example:
cs-api-definition
protected void RadGrid1_SelectedIndexChanged(object sender, EventArgs e)
{
GridTableView tableview = RadGrid1.SelectedItems[0].OwnerTableView;
}

Gets or sets a value determining if the GridItem chould be selected either on the client or on the server.

C#
public GridItemSelectableMode SelectableMode { get; set; }
Property Value:

A value determining if the GridItem chould be selected either on the client or on the server.

Gets or set a value indicating whether the grid item is selected

C#
public bool Selected { get; set; }
Example:
cs-api-definition
protected void RadGrid1_PreRender(object sender, EventArgs e)
{
foreach (GridDataItem dataitem in RadGrid1.MasterTableView.Items)
{
if (dataitem.Selected == true)
{
//do your thing
}
}
}

Methods

C#
protected override void AddAttributesToRender(HtmlTextWriter writer)
Parameters:writerHtmlTextWriter

Overrides: GridTableRow.AddAttributesToRender(HtmlTextWriter)

Calculate column-span value for a cell using column list, when the cell indicated with FromCellIndex should be spanned to ToCellIndex

C#
protected int CalcColSpan(GridColumn[] columns, int FromCellIndex, int ToCellIndex)
Parameters:columnsGridColumn[]

columns - visible property is taken in count

FromCellIndexint

cell inbdex of spanned cell

ToCellIndexint

cell index of next not-spanned cell or -1 for the last cell index

Returns:

int

ColSpan number

C#
protected virtual void CellsDataBound(GridColumn[] columns)
Parameters:columnsGridColumn[]
C#
protected virtual TableCell CreateCellObject()
Returns:

TableCell

C#
protected virtual TableCell CreateCellObject(GridColumn col)
Parameters:colGridColumnReturns:

TableCell

C#
public void ExpandHierarchyToTop()
Example:
cs-api-definition
//get MasterTableView's second (index 1) nested view item
GridNestedViewItem firstLevelNestedViewItem = (GridNestedViewItem)RadGrid1.MasterTableView.GetItems(GridItemType.NestedView)[1];
//get second nested view item at level 2 of the hierarchy
GridNestedViewItem secondLevelNestedViewItem = (GridNestedViewItem)firstLevelNestedViewItem.NestedTableViews[0].GetItems(GridItemType.NestedView)[1];
//get the first item to be expanded
GridItem itemToExpand = secondLevelNestedViewItem.NestedTableViews[0].GetItems(GridItemType.Item)[0];
itemToExpand.ExpandHierarchyToTop();

Use this method to simulate item command event that bubbles to RadGrid and can be handeled automatically or in a custom manner, handling RadGrid.ItemCommand event.

C#
public void FireCommandEvent(string commandName, object commandArgument)
Parameters:commandNamestring

command to bubble, for example 'Page'

commandArgumentobject

command argument, for example 'Next'

C#
protected virtual bool GetExpandedDefaultValue()
Returns:

bool

C#
protected HorizontalAlign LeftAlign()
Returns:

HorizontalAlign

C#
protected override void LoadViewState(object savedState)
Parameters:savedStateobject

Overrides: WebControl.LoadViewState(object)

C#
protected override bool OnBubbleEvent(object source, EventArgs e)
Parameters:sourceobjecteEventArgsReturns:

bool

Overrides: Control.OnBubbleEvent(object, EventArgs)

C#
protected virtual void OnCellDataBound(GridColumn column, TableCell cell)
Parameters:columnGridColumncellTableCell
C#
protected virtual void OnCollapse()
C#
protected virtual void OnExpand()
C#
protected virtual void RemoveEditedChildren()
C#
protected virtual bool RemoveSelectedChildren()
Returns:

bool

C#
protected HorizontalAlign RightAlign()
Returns:

HorizontalAlign

C#
protected virtual void SetEdited(bool value)
Parameters:valuebool
C#
protected virtual void SetItemType(GridItemType itemType)
Parameters:itemTypeGridItemType