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

Accessing RadGrid row cells

3 Answers 737 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Amit
Top achievements
Rank 1
Amit asked on 22 Oct 2010, 12:12 PM
hey everyone,

How are cells of a row accessed in RadGrid,i have used data table as data source and i want to access cells something like this in Gridview.How can i achieve this?...

 if (gvOrders.Rows.Count > 0)
            {
                foreach (GridViewRow row in gvOrders.Rows)
                {
                    InsertOrder(Convert.ToInt32(row.Cells[0].Text), Convert.ToInt32(row.Cells[3].Text));
                }
            }

Thanks
Amit

3 Answers, 1 is accepted

Sort by
0
Princy
Top achievements
Rank 2
answered on 22 Oct 2010, 01:16 PM
Hello Amit,

The following code snippet shows how to access the rows and cells in RadGrid.
C#:
if (RadGrid1.Items.Count > 0)
 {
   foreach (GridDataItem item in RadGrid1.Items)//loops through each grid row
     {
       string v= item["ColumnUniqueName"].Text;//accessing cell using its ColumnUniqueName
     }
 }

And please go through the following documentation which explains how to access cell and rows.
Accessing cells and rows

Thanks,
Princy.
0
Amit
Top achievements
Rank 1
answered on 22 Oct 2010, 01:22 PM
hey,

I have not used columns in radgrid,i have just created a data table in code behind and set it as data source for radgrid.So,i dont have any unique column names.Will it work good with data table by accessing it using data table Column Name?...
0
Accepted
Princy
Top achievements
Rank 2
answered on 22 Oct 2010, 01:51 PM
Hello,


Because of features such as column reordering and grouping, the index of individual columns can change on the client. This means that using indexes to access individual cells in the Cells collection of a row is not a reliable method of obtaining a cell in a particular column.

However, you can use the index of cells to access TableCell as shown below.

foreach (GridDataItem item in RadGrid1.Items)//loops through each grid row
     {
           string v= item.Cells[3].Text;//accessing cell using its ColumnUniqueName
     }

[Note that index starts from 2, since there are two hidden columns at the start]

Thanks,
Princy.
Tags
Grid
Asked by
Amit
Top achievements
Rank 1
Answers by
Princy
Top achievements
Rank 2
Amit
Top achievements
Rank 1
Share this question
or