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

[Solved] The cells in RadGridView

3 Answers 186 Views
GridView
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
Max xu
Top achievements
Rank 1
Max xu asked on 05 Dec 2009, 03:04 PM
Hi,
How can I get the value of one cell in the RadGridView?
And then how can I transmit the value of one cell to another page?

Thank you in advance !

3 Answers, 1 is accepted

Sort by
0
Milan
Telerik team
answered on 07 Dec 2009, 07:12 AM
Hello Max xu,

There are several ways to get a cell value. For example you could do something like that:

var firstRow = this.gridView.ItemContainerGenerator.ContainerFromIndex(0) as GridViewRow;
var firstCell = firstRow.Cells[0] as GridViewCell;
var value = firstCell.Value;

I am not exactly sure if I have understood the second question. Could you elaborate a bit?


All the best,
Milan
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
0
Max xu
Top achievements
Rank 1
answered on 07 Dec 2009, 08:54 AM
Hello,
  There is a CheckBox in CellTemplate of GridView .
I want to get the value of the CheckBox in the whole column one by one .
So that I can judge whether there is any checked CheckBox.


Thank you all !




 
0
Accepted
Milan
Telerik team
answered on 08 Dec 2009, 04:31 PM
Hi Max xu,

 By default RadGridView uses virtualization to boos performance and only the visible rows are available - it is not possible to get visual elements that are not visible. 

If the checkboxes are bound to a property of your data items it is best to loop through the data items instead of the visual elements. For example:

foreach(MyDataItemType dataItem in this.myGridView.Items) 
{
  // checking the property that is bound to a checkbox
  if(dataItem.IsChecked) 
  {
     // do something
  }
}

Another approach is to turn off the vertical virtualization by setting EnableRowVirtualization to false which will create all visual elements but decrease performance. 

If you turn of the virtualization you will be able to do something like that:

foreach(var dataItem in this.myGridView.Items) 
{
    var firstRow = this.gridView.ItemContainerGenerator.ContainerFromItem(dataItem) as GridViewRow; 
    var checkBoxCell = firstRow.Cells[0] as GridViewCell; 
    var checkBox = checkBoxCell.ChildrenOfType<CheckBox>().FirstOrDefault()
      
}

In my opinion te first approach is the preferred way.

Kind regards,
Milan
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
Tags
GridView
Asked by
Max xu
Top achievements
Rank 1
Answers by
Milan
Telerik team
Max xu
Top achievements
Rank 1
Share this question
or