Access the value in the radGrid column

I want to access a value in a radGrid control. Given the image below, I want to access the "Status" value. But I can’t understand it.

I get an error

"Cannot overlay an object of type TripLeg on type Telerik.Web.UI.GridDataItem.

Any ideas on accessing this column?

GridItem

+4
source share
2 answers

I really like Telerik components (more and more I like the Kendo interface), it seems to me that if you want to get the status value, you can use this

string itemValue = dataItem["ColumnUniqueName"].Text; //no need to convert :) 

Take a look at the Documentation for RadGrids ... http://www.telerik.com/help/aspnet-ajax/grid-accessing-cells-and-rows.html

+2
source

You are almost there. You just need to apply the DataItem to the corresponding object. Suppose your data source is IEnumerable<TripLeg> .

Here is an example -

 if (e.Item is GridDataItem) { var item = e.Item as GridDataItem; var tripLeg = e.Item.DataItem as TripLeg; // Cast to appropriate object var status = tripLeg.Status; // var hLink = (HyperLink) item.FindControl("HyperLink1"); // Above code will throw exception if the control is not found. var hLink = item.FindControl("XXXXX") as HyperLink; if(hLink != null) { hLink.Attributes.Add("XXXXX", "XXXXX"); } } 
+3
source

Source: https://habr.com/ru/post/1480178/


All Articles