This is a migrated thread and some comments may be shown as answers.

Radgrid Cell Index ..out by 2?

2 Answers 176 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Stuart
Top achievements
Rank 1
Stuart asked on 24 Oct 2011, 09:29 AM
Hi All

I have a basic Grid with 13 bound cols, based on value at databound I want to change the text in the cell. 

if (e.Item is GridDataItem)
          {
              StockPurchasingVehicle v = (StockPurchasingVehicle)e.Item.DataItem;
              GridDataItem item = (GridDataItem)e.Item;
 
              if (v.OffHireDate == DateTime.MinValue)
              {
                  item.Cells[6].Text = "";
              }
          }

my "OffHireDate" should be index my 4th column, however 6 is the correct index, this seems to be the same for all columns, i.e first index Cells[0] is actually Cells[2].??

I have no hidden cols, or templates.  Not sure how it is counting index, should i use Column Name to access it? rather than index.

Thanks


2 Answers, 1 is accepted

Sort by
0
Accepted
Princy
Top achievements
Rank 2
answered on 24 Oct 2011, 09:56 AM
Hello Stuart,

The column index starts at index 2 beacuse GridExpandColumn and GridRowindicatorColumn are always in front of data columns. You can also access the cell using its ColumnUniqueName like below.

C#:
      if (e.Item is GridDataItem)
          {
              GridDataItem item = (GridDataItem)e.Item;
              string value = item["OffHireDate"].Text;
          }

Thanks,
Princy.
0
Sebastian
Telerik team
answered on 24 Oct 2011, 11:37 AM
And this is actually the recommended way to access cells in grid rows, Stuart. See the resources below for more info:

http://demos.telerik.com/aspnet-ajax/grid/examples/programming/accessingcellsandrows/defaultcs.aspx
http://www.telerik.com/help/aspnet-ajax/grid-accessing-cells-and-rows.html

Best,
Sebastian
the Telerik team
If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to their blog feed now
Tags
Grid
Asked by
Stuart
Top achievements
Rank 1
Answers by
Princy
Top achievements
Rank 2
Sebastian
Telerik team
Share this question
or