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

Custom Functions

4 Answers 531 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
Stuart
Top achievements
Rank 1
Stuart asked on 18 Jun 2008, 09:24 AM
Is there a way I can creater my own custom functions that returns values in Reports?

eg,.
public string GetValue(int val)  
{  
    if(val == 1){  
      return "yes";  
    }else{  
      return "no";  
   }  
so in the field I just have to call

= GetValue(Field.myfield);

I know I can also use the IIF for this but in this specific solution i want to use my own customised function

4 Answers, 1 is accepted

Sort by
0
Accepted
Steve
Telerik team
answered on 18 Jun 2008, 11:43 AM
Hi Stuart,

Yes you can do that, the only thing that you should have in mind is that user functions are public static (Public Shared in VB.NET) methods that always return a value and should always be a member of the respective report class. I've prepared a sample report for your convenience. Give it a spin and let us know if we can be of further help.

Greetings,
Steve
the Telerik team

Instantly find answers to your questions at the new Telerik Support Center
0
Stuart
Top achievements
Rank 1
answered on 18 Jun 2008, 02:05 PM
I am still using the Q3 2007 version of Telerik Reporting might this be the problem

I didnt put his in a class library it is inside a folder in the project itself

The path to the report class is |root|\Reports\Audit.cs

here is my Class code
namespace TNAClient.Reports  
{  
    using System.ComponentModel;  
    using System.Drawing;  
    using System.Windows.Forms;  
    using Telerik.Reporting;  
    using Telerik.Reporting.Drawing;  
      
      
 
    /// <summary> 
    /// Summary description for Report1.  
    /// </summary> 
    public partial class HealthAudit : Report  
    {  
        string groupid;  
        public HealthAudit(string groupid)  
        {  
 
            this.groupid = groupid;  
              
            /// <summary> 
            /// Required for telerik Reporting designer support  
            /// </summary> 
            InitializeComponent();  
            repHead.Value = System.Drawing.Image.FromFile(System.IO.Path.GetFullPath(@"BluZebraLogo.jpg"));  
            auditConnection.ConnectionString = @"Data Source=.\SQLEXPRESS;AttachDbFilename=|DataDirectory|\Database\ClientDB.mdf;Integrated Security=True;User Instance=True";  
            healthAuditDataTableAdapter1.Connection = auditConnection;  
            healthAuditDataTableAdapter1.FillBy(healthAuditData.HealthAuditDataTable , ""+groupid);  
 
              
        }  
        public static string GetHAValue(object val)  
        {  
            int i = int.Parse(val.ToString());  
            if (i == 1)  
            {  
                return "Never";  
            }  
            else if (i == 2)  
            {  
                return "Rarely";  
            }  
            else if (i == 3)  
            {  
                return "50% of Times";  
            }  
            else if (i == 4)  
            {  
                return "Mostly";  
            }  
            else if(i ==5)  
            {  
                return "Always";  
            }  
            else  
            {  
                return "N/A";  
            }  
        }  
    }  
And to call the code I use
=GetHAValue(Fields.A1)

but still get an error
0
Stuart
Top achievements
Rank 1
answered on 18 Jun 2008, 02:26 PM
I saw my mistake , I tried parsing a null value to the static method. sorry problem solved
0
Steve
Telerik team
answered on 18 Jun 2008, 02:47 PM
Hi Stuart,

I've modified the application I've send previously to represent the changes you mention. Still I get the proper behavior and the report is working correctly. Can you look into the modified application and see what differs in your case? What error do you get in yours?

Regards,
Steve
the Telerik team

Instantly find answers to your questions at the new Telerik Support Center
Tags
General Discussions
Asked by
Stuart
Top achievements
Rank 1
Answers by
Steve
Telerik team
Stuart
Top achievements
Rank 1
Share this question
or