Find controls in a grid

4 posts, 0 answers
  1. Ryan
    Ryan avatar
    8 posts
    Member since:
    Mar 2009

    Posted 01 Dec 2009 Link to this post

    I have 2 controls in a grid. A radio button list and a rad date picker. When a user edits or adds info into the grid they can chose between 3 options. only 1 option the date picker is enabled the other 2 options the date picker is disabled. I am trying to do this on Selected Index change on the radio button list, but I can't get the controls of either date picker or radio button list on client or server side. I tried both ways but I am not able to find the solution on this site.

    Thanks
  2. Princy
    Princy avatar
    17421 posts
    Member since:
    Mar 2007

    Posted 01 Dec 2009 Link to this post

    Hello Ryan,

    Here's an example of a similar scenario, which would probably help you achieve the required:
    aspx:
    <telerik:GridTemplateColumn UniqueName="TemplateColumn1">    
          <EditItemTemplate> 
            <asp:RadioButtonList ID="RadioButtonList1" AutoPostBack="true" runat="server" OnSelectedIndexChanged="RadioButtonList1_SelectedIndexChanged"
                <asp:ListItem Text="Option1"
                </asp:ListItem> 
                <asp:ListItem Text="Option2"
                </asp:ListItem> 
                <asp:ListItem Text="Option3"
                </asp:ListItem> 
             </asp:RadioButtonList> 
          </EditItemTemplate> 
    </telerik:GridTemplateColumn> 
    <telerik:GridTemplateColumn UniqueName="TemplateColumn2"
          <EditItemTemplate> 
            <telerik:RadDatePicker ID="DatePicker1" Visible="false" runat="server"
            </telerik:RadDatePicker> 
          </EditItemTemplate> 
    </telerik:GridTemplateColumn> 

    c#:
    protected void RadioButtonList1_SelectedIndexChanged(object sender, EventArgs e) 
        { 
            RadioButtonList rdbtnlist = (RadioButtonList)sender; 
            GridEditableItem editItem = (GridEditableItem)rdbtnlist.NamingContainer; 
            if (rdbtnlist.SelectedItem.Text == "Option1"
            { 
                ((RadDatePicker)editItem.FindControl("DatePicker1")).Visible = true
            } 
            else 
            { 
                ((RadDatePicker)editItem.FindControl("DatePicker1")).Visible = false
            } 
        } 

    Thanks
    Princy.
  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. Daniel Aquere
    Daniel Aquere avatar
    85 posts
    Member since:
    Mar 2011

    Posted 15 Jul 2011 Link to this post

    Hi Princy,

    I´m trying to implement your suggestion, but, the clause "NamingContainer" is not recognized.

    Please, any tip?

    Thanks, best

    Daniel
  5. Princy
    Princy avatar
    17421 posts
    Member since:
    Mar 2007

    Posted 18 Jul 2011 Link to this post

    Hello Daniel,

    I am not sure about the error you are getting. The above sample code is when EditMode is InPlace. For EditForms or PopUp you should access the controls as shown below.
    C#:
    protected void RadioButtonList1_SelectedIndexChanged(object sender, EventArgs e)
    {
            RadioButtonList rdbtnlist = (RadioButtonList)sender;
            GridEditFormItem editItem = (GridEditFormItem)rdbtnlist.NamingContainer;// when EditMode="EditForms"
            GridEditableItem item = (GridEditableItem)rdbtnlist.NamingContainer;//when EditMode="InPlace"
    }

    Thanks,
    Princy.
Back to Top