【问题标题】:How to get the value of a selected row如何获取选定行的值
【发布时间】:2013-07-12 09:01:29
【问题描述】:

我正在尝试从名为 GridView 的 RadGrid 中获取选定的用户名,该用户名是 RadGrid 上名为 UserName 的列。

我试过了:

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

但这会在第一行引发错误:

'索引超出范围。必须是非负数且小于集合的大小。'

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

【问题讨论】:

    标签: c# asp.net telerik radgrid


    【解决方案1】:

    请尝试以下代码 sn-p。

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

    【讨论】:

      猜你喜欢
      • 2012-09-27
      • 1970-01-01
      • 1970-01-01
      • 2012-10-09
      • 2018-08-12
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多