Telerik gets the selected identifier (Get data from the selected Radgrid element)

I can get the selected gridview index, but I want to get the actual data that is inside the grid. I want to select a row in the grid and access the actual value of the column column "Customer ID". The grid is working fine and I can access the SelectedIndexChanged event. Then I tried not to find a way to get the information displayed in the grid. Any help would be greatly appreciated.

Again, I need to access all the data that appears in the codebehind grid form.

+7
source share
3 answers

This requires data keys. Just specify the columns that you want to access as data keys, for example, 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 by line 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"]; } 
+14
source

You can do it as follows:

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

I recommend that you read the documentation on this site http://www.telerik.com/help/aspnet/grid/grdaccessingcellsandrows.html ; this will surely help you with telerik components.

+1
source

Use DataKeys like James Johnson . You cannot access the DataItem property of the DataItem event in SelectedIndexChanged . It will be zero. According to Telerik Documentation "A DataItem is only available when the grid is snapped to data."

When a DateItem available, as in the ItemCreated event, you can cast to the original MyType data MyType :

 private void RadGrid_ItemCreated(object sender, Telerik.Web.UI.GridItemEventArgs e) { if ((e.Item is GridDataItem)) { GridDataItem gridDataItem = (GridDataItem)e.Item; MyType dataItem = (MyType)gridDataItem.DataItem; } } 
0
source

All Articles