I want to access a value in a radGrid control. Given the image below, I want to access the value of "Status". But I can't seem to get it.
I get an error message
"Unable to cast object of type 'TripLeg' to type 'Telerik.Web.UI.GridDataItem'."
Any ideas how to access that column?
You are almost there. You just need to cast DataItem
to appropriate object. Let assume your data source is IEnumerable<TripLeg>
.
Here is the 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");
}
}
I like Telerik Components a lot (altough more and more I like Kendo UI) anyway seems to me that if you want to get the value on the status you could use this
string itemValue = dataItem["ColumnUniqueName"].Text;
//no need to convert :)
Take a look at the Documentation for the RadGrids... http://www.telerik.com/help/aspnet-ajax/grid-accessing-cells-and-rows.html
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With