Loop through checkbox in RadPanelItem

5 posts, 1 answers
  1. Anders
    Anders avatar
    3 posts
    Member since:
    Apr 2010

    Posted 24 Oct 2012 Link to this post

    Hello!

    I add RadPanelItems dynamic and also adding CheckBoxes to each.
    How do loop through all RadPanelItems and find CheckBoxes and get there state?

    // Anders

  2. Boyan Dimitrov
    Admin
    Boyan Dimitrov avatar
    1746 posts

    Posted 26 Oct 2012 Link to this post

    Hello Anders,

    Could you please elaborate a bit more on your scenario so we can test it locally?
    • Could you provide some information about which templates in your project you are using? Here you can find more information about templates in RadPanelBar control.
    • Providing a sample project that demonstrates your scenario (the declaration of the templates and the way you apply them)  would be really helpful.
      Any additional information will be highly appreciated.

    Regards,
    Boyan Dimitrov
    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.
  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. Anders
    Anders avatar
    3 posts
    Member since:
    Apr 2010

    Posted 28 Oct 2012 Link to this post

    Thanks for your reply.
    I want to read the values ​​of all the checkboxes in one postback.
    Here is an example:

    <%@ Page Language="VB" AutoEventWireup="false" CodeFile="Test_statisk.aspx.vb" Inherits="Test_statisk" %>
    <!DOCTYPE html>
    <head runat="server">
        <title></title>
    </head>
    <body>
        <form id="form1" runat="server">
        <div>
            <telerik:RadScriptManager ID="RadScriptManager1" runat="server">
                <Scripts>
                    <asp:ScriptReference Assembly="Telerik.Web.UI" Name="Telerik.Web.UI.Common.Core.js">
                    </asp:ScriptReference>
                    <asp:ScriptReference Assembly="Telerik.Web.UI" Name="Telerik.Web.UI.Common.jQuery.js">
                    </asp:ScriptReference>
                    <asp:ScriptReference Assembly="Telerik.Web.UI" Name="Telerik.Web.UI.Common.jQueryInclude.js">
                    </asp:ScriptReference>
                </Scripts>
            </telerik:RadScriptManager>
         
            <telerik:RadPanelBar ID="radPanelBar" Runat="server" style="margin-right: 117px" Width="353px">
                <Items>
                    <telerik:RadPanelItem runat="server" Text="Main 1">
                        <Items>
                            <telerik:RadPanelItem runat="server" Text="" >
                                <ItemTemplate>
                                    <asp:CheckBox ID="cb11" Text="cb11" runat="server" />
                                </ItemTemplate>
                            </telerik:RadPanelItem>
                        </Items>
                    </telerik:RadPanelItem>
                    <telerik:RadPanelItem runat="server" Text="Main 2">
                        <Items>
                            <telerik:RadPanelItem runat="server" Text="">
                                <ItemTemplate>
                                    <asp:CheckBox ID="cb21" Text="cb21" runat="server" />
                                </ItemTemplate>
                            </telerik:RadPanelItem>
                            <telerik:RadPanelItem runat="server" Text="">
                                <ItemTemplate>
                                    <asp:CheckBox ID="cb22" Text="cb22" runat="server" />
                                </ItemTemplate>
                            </telerik:RadPanelItem>
                        </Items>
                    </telerik:RadPanelItem>
                    <telerik:RadPanelItem runat="server" Text="Main 3">
                        <Items>
                            <telerik:RadPanelItem runat="server" Text="">
                                <ItemTemplate>
                                    <asp:CheckBox ID="cb11" Text="cb31" runat="server" />
                                </ItemTemplate>
                            </telerik:RadPanelItem>
                            <telerik:RadPanelItem runat="server" Text="">
                                <ItemTemplate>
                                    <asp:CheckBox ID="cb11" Text="cb32" runat="server" />
                                </ItemTemplate>
                            </telerik:RadPanelItem>
                        </Items>
                    </telerik:RadPanelItem>
                </Items>
            </telerik:RadPanelBar>
         
            <br />
            <asp:Button ID="btnShowSelected" runat="server" Text="Show selected" />
            <br />
         
        </div>     
            <asp:Label ID="lblText" runat="server"></asp:Label>
        </form>
    </body>
    </html>

    Imports Telerik.Web.UI
     
    Partial Class Test_statisk
        Inherits System.Web.UI.Page
     
        Protected Sub btnShowSelected_Click(sender As Object, e As EventArgs) Handles btnShowSelected.Click
     
            For Each c As RadPanelItem In radPanelBar.GetAllItems
     
                For Each x As Control In c.Items
     
                    lblText.Text &= x.GetType.ToString & "<br>" ' this only returns "Telerik.Web.UI.RadPanelItem"
     
                Next
     
            Next
     
        End Sub
     
    End Class

     

     

  5. Answer
    Boyan Dimitrov
    Admin
    Boyan Dimitrov avatar
    1746 posts

    Posted 29 Oct 2012 Link to this post

    Hello Anders,

    Please note that your last two CheckBox ID are duplicating the CheckBox ID in the first RadPanelBar
    Their ID values should be as following - cb31 and cb32.
    Please use the following approach to achieve the desired functionality:

    Protected Sub btnShowSelected_Click(sender As Object, e As EventArgs) Handles btnShowSelected.Click
        Dim panels As IList(Of RadPanelItem) = radPanelBar.GetAllItems()
        For Each panel As RadPanelItem In panels
            If panel.Items.Count = 0 Then
                Dim checkBox As CheckBox = TryCast(panel.Controls(1), CheckBox)
                If checkBox.Checked = True Then
                    lblText.Text += checkBox.ID
                End If
            End If
        Next
     
    End Sub

    Hope that this will lead you into the right direction.


    Kind regards,
    Boyan Dimitrov
    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.
  6. Anders
    Anders avatar
    3 posts
    Member since:
    Apr 2010

    Posted 29 Oct 2012 Link to this post

    Yes, thank you very much!

    Sincerely
    // Anders
Back to Top
UI for ASP.NET Ajax is Ready for VS 2017