This is a migrated thread and some comments may be shown as answers.

how to get the data from the selected rows in radgrid

2 Answers 1410 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Sourabh
Top achievements
Rank 1
Sourabh asked on 19 Apr 2012, 08:13 AM
Hello friends,

I am using 
GridClientSelectColumn to select the rows and want to access one of the columns data.
I tried the code below but i am getting error 

"Error Cannot convert type 'Telerik.Web.UI.GridItemCollection' to 'Telerik.Web.UI.GridDataItem'"  

protected
 void Button1_Click(object sender, EventArgs e)
{
    foreach(GridDataItem item in RadGrid1.SelectedItems)
   {
      GridDataItem item = (GridDataItem)RadGrid1.SelectedItems;
      String str=item["ColumnUniqueName"].Text;//access the value here
    }
}


Thanks

2 Answers, 1 is accepted

Sort by
0
Shinu
Top achievements
Rank 2
answered on 19 Apr 2012, 08:58 AM
Hi Sourabh,

Try the following code snippet.

C#:
protected void Button1_Click(object sender, EventArgs e)
{
    foreach (GridDataItem item in RadGrid1.SelectedItems)
    {
        String str = item["UniqueNmae"].Text;
    }
}

Another suggestion is to access the selected value in SelectedIndexChanged event.

C#:
void RadGrid1_SelectedIndexChanged(object sender, EventArgs e)
{
    foreach (GridDataItem item in RadGrid1.SelectedItems)
    {
        String str = item["UniqueName"].Text;
    }
}

Note:Set EnablePostBackOnRowClick="true" in client settings.

Thanks,
Shinu.
0
Sourabh
Top achievements
Rank 1
answered on 19 Apr 2012, 01:10 PM
Thank you.
actually i found the solution just some time before...the first option worked for me :)
Thank you again.
Tags
Grid
Asked by
Sourabh
Top achievements
Rank 1
Answers by
Shinu
Top achievements
Rank 2
Sourabh
Top achievements
Rank 1
Share this question
or