C# 如何获取选定行的值
我试图从名为C# 如何获取选定行的值,c#,asp.net,telerik,radgrid,C#,Asp.net,Telerik,Radgrid,我试图从名为GridView的RadGrid中获取所选用户名,用户名是RadGrid上名为username的列 我试过: GridDataItem item =(GridDataItem)GridView.MasterTableView.Items[GridView.SelectedItems[0].ItemIndex]; string lblOrdHeadName = item["UserName"].Text; 但这在第一行中抛出了一个错误,即: “指数超出范围。必须为非负数且小于集合的大
GridView
的RadGrid中获取所选用户名,用户名是RadGrid上名为username
的列
我试过:
GridDataItem item =(GridDataItem)GridView.MasterTableView.Items[GridView.SelectedItems[0].ItemIndex];
string lblOrdHeadName = item["UserName"].Text;
但这在第一行中抛出了一个错误,即:
“指数超出范围。必须为非负数且小于集合的大小。”
有人知道我能做些什么来完成这项工作吗?请尝试下面的代码片段
List<GridDataItem> Items = (from item in RadGrid1.MasterTableView.Items.Cast<GridDataItem>()
where item.Selected
select item).ToList();
if (Items != null && Items.Count > 0)
{
foreach (GridDataItem item in Items)
{
string strUsername = item["UserName"].Text;
}
}
List Items=(来自RadGrid1.MasterTableView.Items.Cast()中的项)
其中项目。已选定
选择项);
if(Items!=null&&Items.Count>0)
{
foreach(项中的GridDataItem项)
{
字符串strUsername=项[“用户名”]。文本;
}
}