Get rows of a Telerik RadGrid

Mahdi Tahsildari picture Mahdi Tahsildari · Aug 4, 2012 · Viewed 30.9k times · Source

I'm working on a RadGrid, and I want to access its rows but it seems it does not have a .Rows property.

Here's what I have tried until now:

enter image description here

How can I access rgCustomers's Rows collection? I want to add a button to each row.

Answer

Daniel picture Daniel · Aug 4, 2012

According to Telerik's documentation,

"Each dynamic row in the grid represents a record from the specified data source. Dynamic rows are represented by the GridDataItem class (a descendent of GridItem).

Each GridTableView has a set of rows (the Items collection) of type GridDataItem."

So you want to use the Items collection of the grid, which is a collection of GridDataItems.

protected void btnLoad_Click(object sender, EventArgs e)
{
  rgCustomers.DataSource = odsCustomers;
  rgCustomers.DataBind();
  foreach (GridDataItem row in rgCustomers.Items)
  {
  }
}