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

Retrieving values from selected rows

1 Answer 176 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Matt
Top achievements
Rank 1
Matt asked on 29 Mar 2008, 12:47 PM
Hi All,

I have a pretty simple task that I am having trouble accomplishing.  I have a GridView that has agent information.  In a hidden column if the GridView I have the AgentId.  I want to allow the user to select a cell (or multiple cells) and click a delete button, which will delete these users from a database. 

I am having trouble retrieving the cell values of the selected cells.  This should something thats easy to do, so I am guessing that I am just missing something here.

As always, thanks in advance for the help!
-Matt

1 Answer, 1 is accepted

Sort by
0
Martin Vasilev
Telerik team
answered on 31 Mar 2008, 03:01 PM
Hi Matt,

Thank you for writing.

You could get selected cells using the SelectedCells generic collection of a RadGridView. Please review the function provided below as reference:

public string GetSelectedCellsValueByColumn(RadGridView radGridView, string columnName)  
{  
    if (radGridView.SelectedCells.Count > 0)  
    {  
        StringBuilder strBuild = new StringBuilder();  
 
        List<GridViewCellInfo> selectedCells = radGridView.SelectedCells;  
 
        for (int i = 0; i < selectedCells.Count; i++)  
        {  
            GridViewRowInfo row = selectedCells[i].RowInfo;  
            strBuild.Append(row.Cells[columnName].Value.ToString());  
            strBuild.Append(", ");  
        }  
 
        return strBuild.ToString(0, strBuild.Length - 2);  
    }  
    else 
    {  
        return null;  
    }  

I hope this was helpful. Do not hesitate to contact me again if you need additional assistance.

All the best,
Martin Vasilev
the Telerik team

Instantly find answers to your questions at the new Telerik Support Center
Tags
GridView
Asked by
Matt
Top achievements
Rank 1
Answers by
Martin Vasilev
Telerik team
Share this question
or