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

Find controls in a grid

3 Answers 69 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Ryan
Top achievements
Rank 1
Ryan asked on 01 Dec 2009, 11:49 PM
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

3 Answers, 1 is accepted

Sort by
0
Princy
Top achievements
Rank 2
answered on 02 Dec 2009, 05:49 AM
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.
0
Daniel Aquere
Top achievements
Rank 2
answered on 15 Jul 2011, 10:11 PM
Hi Princy,

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

Please, any tip?

Thanks, best

Daniel
0
Princy
Top achievements
Rank 2
answered on 18 Jul 2011, 06:23 AM
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.
Tags
Grid
Asked by
Ryan
Top achievements
Rank 1
Answers by
Princy
Top achievements
Rank 2
Daniel Aquere
Top achievements
Rank 2
Share this question
or