Get a reference to a RadDatePicker inside a Repeater server side

4 posts, 0 answers
  1. Matt
    Matt avatar
    6 posts
    Member since:
    Sep 2012

    Posted 30 May 2013 Link to this post

    Hi, I'm trying to use a RadDatePicker inside a Repeater. In the ItemDataBound event, I want to get a reference to the RadDatePicker. However, when I do this:
    RadDatePicker dtStart = item.FindControl("dtStart"as RadDatePicker; 

    I get this error:

    Cannot convert type 'System.Web.UI.Control' to 'Telerik.Web.UI.Skins.RadDatePicker' via a reference conversion, boxing conversion, unboxing conversion, wrapping conversion, or null type conversion 

    I know I've done something similar when the RadDatePicker is inside an edit template of a RadGrid. Is there anyway to accomplish this?
  2. Princy
    Princy avatar
    17421 posts
    Member since:
    Mar 2007

    Posted 30 May 2013 Link to this post

    Hi,
    Try the following code snippet to access the RadDatePicker inside a Repeater.

    C#:
    protected void Repeater1_ItemDataBound(object sender, RepeaterItemEventArgs e)
      {
         /*Loop through the repeater items and access*/
         foreach (RepeaterItem item in Repeater1.Items)
          {
             RadDatePicker RadDatePicker1= (RadDatePicker)item.FindControl("RadDatePicker1");
          }
      }

    Thanks,
    Princy.
  3. Matt
    Matt avatar
    6 posts
    Member since:
    Sep 2012

    Posted 30 May 2013 Link to this post

    I still get an error:

    Cannot convert type 'System.Web.UI.Control' to 'Telerik.Web.UI.Skins.RadDatePicker' 


  4. Matt
    Matt avatar
    6 posts
    Member since:
    Sep 2012

    Posted 30 May 2013 Link to this post

    Ok. I've determined that I can just use an anonymous type and that will give me a RadDatePicker:

    var dtStart = item.FindControl("dtStart");
Back to Top