Radio Button in Tree list find control

10 posts, 0 answers
  1. Prassin
    Prassin avatar
    87 posts
    Member since:
    Jun 2012

    Posted 29 Jun 2012 Link to this post

    Hi all,

    I have a tree list and 2 radio button under this tree list... when i try to find the radio button on my tree list its state has been always checked false.. i have assigned the auto postback .. but its not working it seems..

    Source is 
    <td>
      <asp:RadioButton ID="rbDepPer" runat="server" GroupName="dep" />
      <telerik:RadNumericTextBox ID="txtBoxDepPer" Text='<%# Bind("DepPer") %>' runat="server">
      </telerik:RadNumericTextBox>
     </td>
      <td>
      Depreciation Year:
     </td>
     <td>
    <asp:RadioButton ID="rbDepYear" runat="server" GroupName="dep" />
     <telerik:RadNumericTextBox ID="txtBoxDepYear" Text='<%# Bind("DepYear") %>' runat="server"
     Width="300px" >
     </telerik:RadNumericTextBox>
       </td>
    Code Behind
    Protected Sub RadTreeList1_ItemCreated(ByVal sender As Object, ByVal e As Telerik.Web.UI.TreeListItemCreatedEventArgs) Handles RadTreeList1.ItemCreated
           If TypeOf e.Item Is TreeListEditFormItem AndAlso DirectCast(e.Item, TreeListEditFormItem).IsInEditMode Then
               Dim item As TreeListEditableItem = TryCast(e.Item, TreeListEditableItem)
               Dim rad1 As RadioButton = DirectCast(item.FindControl("rbDepPer"), RadioButton)
               Dim rad2 As RadioButton = DirectCast(item.FindControl("rbDepYear"), RadioButton)
               Dim textBox = TryCast(item.FindControl("txtBoxDepPer"), RadNumericTextBox)
               Dim textBox2 = TryCast(item.FindControl("txtBoxDepYear"), RadNumericTextBox)
               rad1.AutoPostBack = True
               rad2.AutoPostBack = True
               If rad1.Checked = True Then
                   textBox.Enabled = True
                   textBox2.Enabled = False
               ElseIf rad2.Checked = True Then
                   textBox2.Enabled = True
                   textBox.Enabled = False
               End If
           End If
       End Sub


    I need to set visibility of that text box control while clicking the radio button..
    Please help..


    Regards,

    Prassin
  2. Prassin
    Prassin avatar
    87 posts
    Member since:
    Jun 2012

    Posted 03 Jul 2012 Link to this post

    Hi all..

    On a big trouble.. please help...


    Regards

    Prassin
  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. Marin
    Admin
    Marin avatar
    1044 posts

    Posted 05 Jul 2012 Link to this post

    Hello,

     You can handle the CheckedChanged event of the RadioButton - this way you can perform the necessary action when the button is checked or unchecked.

    Private Sub rad_CheckedChanged(sender As Object, e As EventArgs) Handles rbDepPer.CheckedChanged
        Dim rad = TryCast(sender, RadioButton)
        Dim textBox = TryCast(TryCast(rad.NamingContainer, TreeListDataItem).FindControl("txtBoxDepPer"), RadNumericTextBox)
        textBox.Visible = rad.Checked
    End Sub

    All the best,
    Marin
    the Telerik team
    If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to their blog feed now.
  5. Prassin
    Prassin avatar
    87 posts
    Member since:
    Jun 2012

    Posted 05 Jul 2012 Link to this post

    Hi Marin,


    how can i get that radio button checked event in code behind... tree list containing that particular radio button... 

    please help..

    Regards

    Prassin
  6. Princy
    Princy avatar
    17421 posts
    Member since:
    Mar 2007

    Posted 05 Jul 2012 Link to this post

    Hello,

    Try attaching the event as shown below.
    C#:
    protected void RadTreeList1_ItemCreated(object sender, Telerik.Web.UI.TreeListItemCreatedEventArgs e)
    {
     if (e.Item is TreeListEditFormItem && ((TreeListEditFormItem)e.Item).IsInEditMode)
     {
       TreeListEditFormItem item = e.Item as TreeListEditFormItem ;
      RadioButton rad2 = (RadioButton)item.FindControl("RadioButton2");
      rad2.CheckedChanged += new EventHandler(rad2_CheckedChanged);
     }
    }
    void rad2_CheckedChanged(object sender, EventArgs e)
    {
    }

    Thanks,
    Princy.
  7. Prassin
    Prassin avatar
    87 posts
    Member since:
    Jun 2012

    Posted 05 Jul 2012 Link to this post

    Hi Princy..

    am work with vb.net... in the case i try to convert this code as vb.. its show an error like "Public Event CheckedChanged (sender as object, e as system.eventArgs)is an event and cannot be called directly use a RaiseEvent statement to Raise an Event"

    i dont know what i have to do for this..


    Prassin
  8. Princy
    Princy avatar
    17421 posts
    Member since:
    Mar 2007

    Posted 06 Jul 2012 Link to this post

    Hello,

    Here is the code in VB.
    VB:
    Protected Sub RadTreeList1_ItemCreated(sender As Object, e As Telerik.Web.UI.TreeListItemCreatedEventArgs)
        If TypeOf e.Item Is TreeListEditFormItem AndAlso DirectCast(e.Item, TreeListEditFormItem).IsInEditMode Then
            Dim item As TreeListEditFormItem = TryCast(e.Item, TreeListEditFormItem)
            Dim rad2 As RadioButton = DirectCast(item.FindControl("RadioButton2"), RadioButton)
            rad2.CheckedChanged += New EventHandler(rad2_CheckedChanged)
        End If
    End Sub
    Private Sub rad2_CheckedChanged(sender As Object, e As EventArgs)
    End Sub

    Thanks,
    Princy.
  9. Prassin
    Prassin avatar
    87 posts
    Member since:
    Jun 2012

    Posted 06 Jul 2012 Link to this post

     Hi Princy.. 
    Thanks for you replay...
    But i am getting the same error..

    Please find the attachment...


    Regards,

    Prassin
  10. Marin
    Admin
    Marin avatar
    1044 posts

    Posted 06 Jul 2012 Link to this post

    Hello,

     The proper way to add an event handler in VB code-behind is the following:

    AddHandler rad2.CheckedChanged, AddressOf rad2_CheckedChanged

    The code converters sometimes do not handle this very well.

    Kind regards,
    Marin
    the Telerik team
    If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to their blog feed now.
  11. Prassin
    Prassin avatar
    87 posts
    Member since:
    Jun 2012

    Posted 07 Jul 2012 Link to this post

    Hi all,,

    When i try to achieve my requirement that time its show and error message ... please look up the code and source .. and also attached error message to this post.. please look up and help...
    Aspx:
    <fromtemplate>
    <table>
       <tr>
          <td>
               Depreciation %:
              </td>
               <td>
           <asp:RadioButton ID="rbDepPer" runat="server" GroupName="dep" />
           <telerik:RadNumericTextBox ID="txtBoxDepPer" Text='<%# Bind("DepPer") %>' runat="server">
                </telerik:RadNumericTextBox>
                       </td>
                      <td>
                      Depreciation Year:
                        </td>
                       <td>
                      <asp:RadioButton ID="rbDepYear" runat="server" GroupName="dep" />
      <telerik:RadNumericTextBox ID="txtBoxDepYear" Text='<%# Bind("DepYear") %>' runat="server"
                         Width="300px" >
                      </telerik:RadNumericTextBox>
               </td>
                     </tr>
    </table>
    </fromtemplate>
    Code Behind

    Protected Sub RadTreeList1_ItemCreated(ByVal sender As Object, ByVal e As Telerik.Web.UI.TreeListItemCreatedEventArgs) Handles RadTreeList1.ItemCreated
          
           If TypeOf e.Item Is TreeListEditFormItem AndAlso DirectCast(e.Item, TreeListEditFormItem).IsInEditMode Then
               Dim item As TreeListEditFormItem = TryCast(e.Item, TreeListEditFormItem)
               Dim rad1 As RadioButton = DirectCast(item.FindControl("rbDepPer"), RadioButton)
               Dim rad2 As RadioButton = DirectCast(item.FindControl("rbDepYear"), RadioButton)
               rad1.AutoPostBack = True
               rad2.AutoPostBack = True
               AddHandler rad1.CheckedChanged, AddressOf rad1_CheckedChanged
               AddHandler rad2.CheckedChanged, AddressOf rad2_CheckedChanged
               Dim rad = TryCast(sender, RadioButton)
              
           End If
       End Sub
     
       Private Sub rad2_CheckedChanged(ByVal sender As Object, ByVal e As EventArgs)
           Dim rad = TryCast(sender, RadioButton)
           Dim textBox = TryCast(TryCast(rad.NamingContainer, TreeListDataItem).FindControl("txtBoxDepPer"), RadNumericTextBox)
           textBox.Enabled = rad.Checked
       End Sub
       Private Sub rad1_CheckedChanged(ByVal sender As Object, ByVal e As EventArgs)
           Dim rad = TryCast(sender, RadioButton)
           Dim textBox2 As RadNumericTextBox = TryCast(TryCast(rad.NamingContainer, TreeListDataItem).FindControl("txtBoxDepYear"), RadNumericTextBox)
           textBox2.Enabled = rad.Checked
       End Sub


    please find the attachment 

    Regards,

    Prassin
Back to Top
UI for ASP.NET Ajax is Ready for VS 2017