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

ForEACH record in Datagrid

7 Answers 142 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Nikhil
Top achievements
Rank 1
Nikhil asked on 22 Jun 2009, 02:50 PM
Hi ,
I am new to Silverlight + telerik and want to know a how can i traverse through each record in a sillverlight Telerik  Datagrid.

What I am looking for is a Silverlight equivalent code for below AJax code


      foreach (GridDataItem Item  in SourceRadGrid.Items)
          {
               if (((CheckBox)Item["TemplateColumnCheckBox"].FindControl("CheckBox1")).Checked)
                {
                   
                    LineNo = Item.Cells[3].Text.ToString();
     
                }

         }
Experts please guide

7 Answers, 1 is accepted

Sort by
0
Casey
Top achievements
Rank 1
answered on 22 Jun 2009, 04:09 PM
I have the same question.

I have a checkbox as the first column of each row and I want to implement a SelectAll and UnselectAll column.

The column is not bound, so I think it makes sense to loop through and just check the items.

casey
0
Nikhil
Top achievements
Rank 1
answered on 22 Jun 2009, 04:43 PM
Checkbox is just an example i put,,,,but i really need to find a way ,,,,to travese through each record item in grid.. and get their contents
0
Nikhil
Top achievements
Rank 1
answered on 23 Jun 2009, 02:08 PM
Can somebody please help? I's really urgent
0
Casey
Top achievements
Rank 1
answered on 24 Jun 2009, 05:09 PM
It is disappointing that no one has responded...

This gets the data out of the datacolumns.. but my checkbox column returns as nulll

 

 

for (int ii = 0; ii < dataGrid.Items.Count; ii++)

 

{

 

var row = dataGrid.ItemsControl.ItemsGenerator.GenerateItemAtIndex(ii) as GridViewRow;

 

 

object cellValue = null;

 

 

for (int iCell = 0; iCell < dataGrid.Columns.Count; iCell++)

 

{

cellValue = row.Cells[iCell].Content;

 

if (iCell == 0)

 

{

 

if (cellValue is CheckBox)

 

{

 

CheckBox c = (CheckBox)cellValue;

 

c.IsChecked =

true;

 

}

 

}

}

}

0
Casey
Top achievements
Rank 1
answered on 24 Jun 2009, 08:42 PM
Got it.. Still don't understand why previous post returned null.

 

for (int i = 0; i < dataGrid.Items.Count; i++)

 

{

 

        var row = dataGrid.ItemsControl.ItemsGenerator.GenerateItemAtIndex(i) as GridViewRow;

 

 

        GridViewCell firstCell2 = row.Cells.Cast<GridViewCell>().FirstOrDefault();

 

 

        if (firstCell2 != null)

 

        {

            ((

CheckBox)firstCell2.ChildrenOfType<CheckBox>().FirstOrDefault()).IsChecked=true;

 

        }

}

0
Nikhil
Top achievements
Rank 1
answered on 25 Jun 2009, 02:48 PM
Hi

Casey

I am still  getting NULL for the first column...i m not sure why it is working for you , Below in my code ,.,,,changes done in your code to implement radio button and Chckbox

for (int i = 0; i < RadGridView1.Records.Count; i++)

 

{

 

var row = RadGridView1.ItemsControl.ItemsGenerator.GenerateItemAtIndex(i) as GridViewRow;

 

 

GridViewCell firstCell2 = row.Cells.Cast<GridViewCell>().FirstOrDefault();

 

 

 

if (firstCell2 != null)  

 

{

((

RadioButton)firstCell2.ChildrenOfType<RadioButton>().FirstOrDefault()).IsChecked = true;

 

 

break;

 

}

}



0
Kiran G
Top achievements
Rank 1
answered on 04 Apr 2012, 08:01 AM
Hi Frens,

Use the following code to read the silverlight datagrid....



foreach (DataGridRow row in GetDataGridRows(dgParams))
{
   
// parse your gird controls like below
   
TextBlock txtParamName = dgParams.Columns[0].GetCellContent(row) as TextBlock;
   
TextBox txtParamValue = dgParams.Columns[1].GetCellContent(row) as TextBox;
}
private List


*Note : it will read only visible grid controls.

Tags
GridView
Asked by
Nikhil
Top achievements
Rank 1
Answers by
Casey
Top achievements
Rank 1
Nikhil
Top achievements
Rank 1
Kiran G
Top achievements
Rank 1
Share this question
or