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

DataField and c# extensions?

2 Answers 80 Views
Grid
This is a migrated thread and some comments may be shown as answers.
kyle
Top achievements
Rank 1
kyle asked on 27 Feb 2009, 04:19 PM
Does the telerik ajax grid support setting a column DataField to a C# extension?
Right now it doesnt error, but it is not returning the value in the grid.


        public static string CustomerNameWhole(this ResResidentSearchDataItem item)
        {
            return item.FirstName + " " + item.LastName;
        }

2 Answers, 1 is accepted

Sort by
0
Georgi Krustev
Telerik team
answered on 04 Mar 2009, 10:14 AM
Hi Kyle,

I am not sure if I fully understand what your scenario is, but there should be no problem using extension methods. In attempt to test this functionality I created an extension method for the GridDataItem, which returns string value.

Here is the code snippet showing what I have done:
    public static class GridExtensions 
    { 
        public static string ProductNameWhole(this GridDataItem item) 
        { 
            return String.Format("Product Name: {0}", item["ProductName"].Text); 
        } 
    } 
    protected void RadGrid1_ItemDataBound(object sender, GridItemEventArgs e) 
    { 
        if (e.Item is GridDataItem)  
        { 
            var item = e.Item as GridDataItem; 
 
            string result = item.ProductNameWhole(); 
        } 
    } 

The result variable will be populated with the returned string value from the extension method.

All the best,
Georgi Krustev
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Check out the tips for optimizing your support resource searches.
0
kyle
Top achievements
Rank 1
answered on 04 Mar 2009, 10:17 AM
thanks so much!  I was trying to do it for the item that was bound to the grid not the gridDataItem... that actually makes sense..

Thank you Telerik!
Tags
Grid
Asked by
kyle
Top achievements
Rank 1
Answers by
Georgi Krustev
Telerik team
kyle
Top achievements
Rank 1
Share this question
or