Click here to Skip to main content
15,884,176 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi I have a radlistbox with SelectionMode="Multiselect". I want to get the count of checked items of listbox on button click. I tried to get the count by finding control on button click event but i am not able to find the control.


But I am not able to find control. Can anyone suggest a better way to do this. My main objective is to get count of checked items of list box on button click

What I have tried:

HTML Code:
ASP.NET
<telerik:radajaxpanel id="RadAjaxPanel1" runat="server" width="100%">

<div>

<asp:table>

<asp:tablerow>
                <asp:tableheadercell>
                <telerik:radlabel id="RadLabel_abc" runat="server" text="ABC">
                
<asp:tablerow>

<asp:tablecell>

<telerik:radlistbox id="rlbAbc" runat="server" 
="" height="100px" width="480px" allowtransfer="false" allowtransferondoubleclick="false" transfertoid="rlbChosen" enabledraganddrop="true" onclienttransferring="rlbAbc_OnClientTransferring" checkboxes="true" buttonsettings-showtransferall="false" enableviewstate="false" selectionmode="Multiple">

</div>


.VB File
VB
Protected Sub RadButton_AddToList_Click(sender As Object, e As EventArgs)

GetSelectedItemText("rlbABC")

End Sub

Public Function GetSelectedItemText(ByVal controlID As String) As String
        Dim theListbox As RadListBox = CType(FindControl(controlID), RadListBox)
        For idx As Integer = 0 To theListbox.Items.Count - 1
            Dim li As RadListBoxItem = theListbox.Items(idx)

            If theListbox.Items(idx).Selected = True Then
                Return theListbox.Items(idx).Text
            End If
        Next

        Return Nothing
    End Function
Posted
Updated 19-Nov-19 21:46pm
v2

1 solution

ASP.NET
<telerik:radlistbox id="rlbAbc" runat="server" 


VB
GetSelectedItemText("rlbABC")

You have different character cases in the HTML and VB.
 
Share this answer
 
Comments
tishi208 21-Nov-19 23:13pm    
@Richard...Thats not the case in actual code. I had renamed the controls here and thats the typo which i had done at the time i was doing rename but in actual code thats not the issue. Can you please suggest something else
Richard MacCutchan 22-Nov-19 3:24am    
The only thing I cab suggest is using the debugger to find out what is happening when you run the code.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900