2013-07-12 4 views
1

RadGrid에서 선택한 사용자 이름을 GridView, 사용자 이름을 UserName이라고하는 RadGrid의 열로 가져 오려고합니다.선택한 행의 값을 얻는 방법

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; 
     } 
    } 
관련 문제