Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Telerik getting selected ID (Get data from Radgrid selected item)

I can get the selected index of the gridview but i want to get the actual data that is inside the grid. I want to select a row in the grid and be able to access the "Client Id" column's actual data value. The grid is working fine and I am able to access the SelectedIndexChanged event. I have then been trying with no luck to find a way to get the information that is displayed in the grid. Any help would be greatly appreciated.

Again, I need to get access to all data that is displayed in the grid form the codebehind.

like image 839
joncodo Avatar asked Sep 14 '11 17:09

joncodo


2 Answers

This is what data keys are for. Just designate the columns you want to access as data keys, like in the example shown below.

<telerik:RadGrid ID="RadGrid1" runat="server" ...>
    <MasterTableView DataKeyNames="Column1, Column2, Column3" ...>
        ...
    </MasterTableView>
</telerik>

Once the data keys have been assigned in the markup, you can access them in code-behind by row, or using the SelectedValues property.

if (RadGrid1.SelectedItems.Count > 0)
{
    //access a string value
    string column1 = RadGrid1.SelectedValues["Column1"].ToString();

    //access an integer value
    int column2 = (int)RadGrid1.SelectedValues["Column2"];
}
like image 125
James Johnson Avatar answered Nov 15 '22 12:11

James Johnson


You could do it like this:

foreach (GridDataItem item in RadGrid1.MasterTableView.Items)
{
    if (item.selected == true)
        string mydata = item["ColumnName"].Text;
}

I recommend you read the documentation on this site http://www.telerik.com/help/aspnet/grid/grdaccessingcellsandrows.html; it will sure help you a lot with Telerik components.

like image 30
Zaphood Avatar answered Nov 15 '22 12:11

Zaphood