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
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
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;
}
}
}
}
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;
}
}
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;
}
}
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.