我在每行中都有一个带复选框的radgride。我希望当我点击按钮时,它会检查每行检查的id,放入变量.. 我知道gridview的这段代码,但我不知道radgrid的这段代码相当于
foreach (GridViewRow rw in grid1.Rows)
{
CheckBox chkBx = (CheckBox)rw.FindControl("Check");
if (chkBx != null && chkBx.Checked)
{
id= grid1.Rows[0].Cells[3].Text.ToString();
}
}
答案 0 :(得分:1)
if (RadGrid1.Items.Count > 0)
{
foreach (GridDataItem item in RadGrid1.Items)//loops through each grid row
{
CheckBox chkBx = (CheckBox)rw.FindControl("Check");
if (chkBx != null && chkBx.Checked)
{
//string v= item["ColumnUniqueName"].Text;
string v= item.Cells[3].Text; //accessing cell using its ColumnUniqueName
}
}
}
有关Radgrid行和单元格访问的详细信息,请查看http://www.telerik.com/help/aspnet-ajax/grid-accessing-cells-and-rows.html
答案 1 :(得分:0)
试试这个:http://www.telerik.com/community/forums/aspnet-ajax/grid/loop-through-radgrid.aspx
foreach(GridItem rw in grid1.Items)
{
CheckBox chkBx = rw.FindControl("Check") as CheckBox ;
if (chkBx != null && chkBx.Checked)
{
string id = rw.Cells[3].Text;
}
}