C# .NET - Find RadComboBox control on checkedchanged

Asked By Bea Kim on 16-Feb-12 12:50 AM

I have a RadGrid contains Checkboxes and a combobox. What I want to do is to find the RadCombobox Control inside the radGrid on chkMenu_CheckedChange

<


telerik:GridTemplateColumn UniqueName="AccessID"



SortExpression="AccessName" Allowfiltering="false" Visible="false">



<ItemTemplate>



<asp:Label runat="server" ID="lblID" Text='<%# Eval("AccessID") %>' Visible="false"/>



</ItemTemplate>



<EditItemTemplate>



<telerik:RadTextBox runat="server" Width="500px" ID="txtAccessID" Text='<%# Eval("AccessID") %>' Visible="false"/>



<table>





<tr>



<td valign="top" colspan="2">

<asp:CheckBox ID="chkMenu" Text="Menu" runat="server" OnCheckedChanged="chkMenu_CheckedChange" AutoPostBack="true"/>  

<asp:CheckBox ID="chkTreeNode" Text="Tree Node" runat="server" />  


<asp:CheckBox ID="chkTab" Text="Tab" runat="server" />  


<asp:CheckBox ID="chkObject" Text="Object" runat="server" />


</td>



</tr>



<tr>



<td>

  Department:

</td>


<td valign="top">

<asp:HiddenField ID="hdnDept" runat="server" Value='<%# Eval("DepartmentID") %>' />

<telerik:RadComboBox ID="ddlDepartmentID" runat="server" Width="500px" Visible="false">


<Items>


  <telerik:RadComboBoxItem Text="" />


</Items>


</telerik:RadComboBox>


</td>



</tr>



</table>



</EditItemTemplate>



</telerik:GridTemplateColumn>




protected

void chkMenu_CheckedChange(object source, EventArgs e)

{

//Code for Checkbox and RadCombobox Find Control

if (chkMenu.Checked == true)

{

ddlDepartment.Visible =

true;

}

}

}

Rajat replied to Bea Kim on 16-Feb-12 12:56 AM

you cant directly get the checkbox .It is within a Grid and the compile ould not know which checkbox you are referring to

I believe you would need to
1. get the row
2. find control ( the checkbox ie) for that row and typecast it as a  check box
then use that control to do logic operations

i am sorry , i am not at my workstation,so could not type in the code .If you face issues do post back .
Bea Kim replied to Rajat on 16-Feb-12 01:13 AM

Hi,

What do I need is to check if the chkMenu.checked == true then Radcombobox will be visible.
I try this code but it gives error on radcombobox findcontrol. Is there any way to find radcombobox control? thanks

protected void chkMenu_CheckedChange(object source, EventArgs e)

{


CheckBox chkMenu = (CheckBox)source;

RadComboBox ddlDepartment = (RadComboBox)RadGrid1.FindControl("ddlDepartment");


if (chkMenu.Checked == true)

{

ddlDepartment.Visible =

true;

}


}

Somesh Yadav replied to Bea Kim on 16-Feb-12 04:24 AM
Hi,

Try this,

ASPX:
 
<telerik:RadComboBox ID="RadComboBox2" runat="server">  
    <Items>
      <telerik:RadComboBoxItem runat="server" Text="RadComboBoxItem1" Value="RadComboBoxItem1" />
      <telerik:RadComboBoxItem runat="server" Text="RadComboBoxItem2" Value="RadComboBoxItem2" />
    </Items>
    <ItemTemplate>
      <asp:CheckBox ID="A" runat="server" />
      <asp:CheckBox ID="B" runat="server" />
      <asp:CheckBox ID="C" runat="server" />
      <asp:CheckBox ID="D" runat="server" />
      <asp:RadioButton ID="P" GroupName="g" runat="server" AutoPostBack="True"
        OnCheckedChanged="CheckedChanged" />
      <asp:RadioButton ID="Q" GroupName="g" Checked="true" runat="server"   
        AutoPostBack="True" OnCheckedChanged="CheckedChanged" />
    </ItemTemplate>
</telerik:RadComboBox>

C#:
 
protected void CheckedChanged(object sender, EventArgs e)  
{  
    RadioButton RButton = (RadioButton) sender;  
    RadComboBoxItem item = (RadComboBoxItem)RButton.NamingContainer;  
    if (RButton.ID == "P")  
    {  
      (item.FindControl("B") as CheckBox).Enabled = false;  
    }  
    else
    {  
      (item.FindControl("B") as CheckBox).Enabled = true;  
    }  
}

Hope it helps you.