New to Telerik UI for ASP.NET AJAX? Download free 30-day trial

How to pass parameters to a custom database provider


How to pass parameters to a custom database provider


There are quite a few scenarios in which you may need to pass a parameter to your custom database provider. For example, suppose that you want to apply a filter to the appointments collection of RadScheduler and leave only appointments with a specific Resource. The way to accomplish this is to pass a parameter to the custom provider which will carry the key for your filter rule.


  1. Create your own class in App_Code which inherits from the Page class. In the example, I create the MyPage.cs file.
  2. Define the properties which will be passed to the provider in MyPage.cs.

        private string _myparam;  

    public string MyParam

    get { return _myparam; }  
    set { _myparam = value; }  


    1. Set your page to inherit from MyPage:
      C# public partial class _Default : MyPage
    2. Find and cast MyPage in the provider like this:

      using (DbConnection conn = OpenConnection())  
           DbCommand cmd = DbFactory.CreateCommand();  
           cmd.Connection = conn;  
           cmd.CommandText = "SELECT [ClassID], [Subject], [Start], [End], [RecurrenceRule], [RecurrenceParentId] FROM [DbProvider_Classes]";  
           MyPage page1 = (MyPage) owner.Page;  
           string param1 = page1.MyParam;  
           using (DbDataReader reader = cmd.ExecuteReader())  

    3. Once you have access to the parameter, you can implement your custom logic with it. For example, the highlighted code below will load only appointments with Text for the Teacher resource equal to the value of the parameter:

      while (reader.Read())  
        Appointment apt = new Appointment();  
           apt.Owner = owner;  
           apt.ID = reader["ClassID"];  
           apt.Subject = Convert.ToString(reader["Subject"]);  
           apt.Start = DateTime.SpecifyKind(Convert.ToDateTime(reader["Start"]), DateTimeKind.Utc);  
           apt.End = DateTime.SpecifyKind(Convert.ToDateTime(reader["End"]), DateTimeKind.Utc);  
           apt.RecurrenceRule = Convert.ToString(reader["RecurrenceRule"]);  
           apt.RecurrenceParentID = reader["RecurrenceParentId"] == DBNull.Value ? null : reader["RecurrenceParentId"];  
           if (apt.RecurrenceParentID != null)  
                 apt.RecurrenceState = RecurrenceState.Exception;  
                 if (apt.RecurrenceRule != string.Empty)  
                    apt.RecurrenceState = RecurrenceState.Master;  
           if (apt.Resources.GetResourceByType("Teacher") != null)  
                 if (apt.Resources.GetResourceByType("Teacher").Text == param1)  

    6. Now, because of step 2 and 3, you can easily access the new property MyParam and assign it a value in code-behind of your page:

       protected void Page_Load(object sender, EventArgs e)
    //Show only lectures by Mr John Doe
    MyParam = "Mr John Doe";
      //Show only lectures by Mrs Jane Smith  
      //MyParam = "Mrs Jane Smith";           


    Attached is a demo project.
In this article