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

Looping through labels of selected items

2 Answers 40 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Janaki
Top achievements
Rank 1
Janaki asked on 01 Nov 2012, 04:08 AM
Hi all,

In my radgrid, I can select multiple rows at  a time. How can I loop through labels of the selected items? Please help me to find an answer.

Thanks in advance

2 Answers, 1 is accepted

Sort by
0
Accepted
Shinu
Top achievements
Rank 2
answered on 01 Nov 2012, 04:25 AM
Hi,

Please take a look into the following code snippet for looping through selected items on a Button click event.

C#:
protected void Button1_Click(object sender, EventArgs e)
{
    foreach (GridDataItem item in RadGrid1.SelectedItems)
    {
        Label lbl = (Label)item.FindControl("Label1");
    }
}

Thanks,
Shinu.

0
Tsvetoslav
Telerik team
answered on 01 Nov 2012, 08:03 AM
Hello Janaki,

If you need the raw field values of the items without any custom html formatting you should use the following code:
protected void Button1_Click(object sender, EventArgs e)
  
{
  
    foreach (GridDataItem item in RadGrid1.SelectedItems)
  
    {
  
        Hashtable fieldValues = new Hashtable()
        item.ExtractValues(fieldValues);
        //now fieldValues should contain a key-value pair collection containing the column values for the selected item
  
    }
  
}



Regards, Tsvetoslav
the Telerik team
If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to their blog feed now.
Tags
Grid
Asked by
Janaki
Top achievements
Rank 1
Answers by
Shinu
Top achievements
Rank 2
Tsvetoslav
Telerik team
Share this question
or