2013-07-12 49 views
1

我想从RadGrid中调用GridView所选的用户名,用户名是RadGrid上名为UserName的列。如何获得选定行的值

我曾尝试:

GridDataItem item =(GridDataItem)GridView.MasterTableView.Items[GridView.SelectedItems[0].ItemIndex]; 
string lblOrdHeadName = item["UserName"].Text; 

但是,这会引发错误的拳头行说:

人指数超出范围。必须是非负面的,并且小于收藏的大小。“

有谁知道我能做些什么来完成这项工作?

回答

0

请试试下面的代码片段。

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