Avatar of Victor  Charles
Victor Charles
Flag for United States of America asked on

Help with setting values when clicking on checkboxex of a combobox control

Hello,

When I click on several checkboxes to set a variables xx,yy,zz,ww to 1 for rows checked my code below (Msgbox ("Test") never executes, any ideas what is causing this problem?

Code:

  Protected Sub Button131_Click(ByVal sender As Object, ByVal e As EventArgs) Handles Button131.Click

        Dim str1 As String = Nothing
        xx = 0
        yy = 0
        zz = 0
        ww = 0
        Dim ctrlA As Control = MultiView1.FindControl("C1SDeactivation")
        For i = 0 To C1SDeactivation.Items.Count - 1
            If C1SDeactivation.Items(i).Selected Then
                MsgBox("Test") *****Does not execute
                If i = 0 Then
                    xx = 1
                End If
                If i = 1 Then
                    yy = 1
                End If
                If i = 2 Then
                    zz = 1
                End If
                If i = 3 Then
                    ww = 1
                End If
            End If
            MsgBox(i)
        Next
        MsgBox(xx)
        MsgBox(yy)
        MsgBox(zz)
        MsgBox(ww)
End Sub

Control:

<cc1:C1ComboBox ID="C1SDeactivation" runat="server"
                         OpenDropDownOnLoad="True"
                         SelectionMode="Multiple" Width="180px"    
                         onselectedindexchanged="C1SDeactivationA_SelectedIndexChanged"
                         OnClientSelectedIndexChanged ="C1SDeactivationA_OnClientSelectedIndexChanged"
                         AccessKey="" ToolTip="" HideDropDownListOnBlur="False"
                         DropDownPositioningMode="BottomCenter" DropDownHeight="100"
                         Text="Select (Multiple Allowed)" ShowTrigger="False" IsEditable="False">
                          <ItemsTemplate>
                            <asp:CheckBox ID="SDeactivation" runat="server" onChange="setColor(); " />
                             <%# DataBinder.Eval(Container.DataItem, "SDeactivation")%>
                         </ItemsTemplate>
                     </cc1:C1ComboBox>


Thanks,

Victor
ASP.NETVisual Basic.NET.NET Programming

Avatar of undefined
Last Comment
Victor Charles

8/22/2022 - Mon
Nasir Razzaq

Its because the following condition

 If C1SDeactivation.Items(i).Selected Then

never evaluates to true.
Victor Charles

ASKER
I know but I don't know why because I did select the rows when I clicked on the checkboxes.
markmiddlemist

I may be wrong, but I think the checkbox property you are looking for is Checked not Selected ( you my need to cast the control to checkbox to access this)
Experts Exchange is like having an extremely knowledgeable team sitting and waiting for your call. Couldn't do my job half as well as I do without it!
James Murphy
Victor Charles

ASKER
I'm afraid checked is not a propery of the combobox, how do I cast the control tyo checkbox?
Thanks.
markmiddlemist

Victor Charles

ASKER
Hi Unfortunately,

I still can't figure out why the code I initially posted doesn't work now, it thought worked a few weeks ago, can you please take a closer look at the syntax to see why
 "If C1SDeactivation.Items(i).Selected then" is not executing even when I select the rows.

I think the problem might be because the ID of my checkbox is SDeactivation as shown below:

  <ItemsTemplate>
                            <asp:CheckBox ID="SDeactivation" runat="server" onChange="setColor(); " />
                             <%# DataBinder.Eval(Container.DataItem, "SDeactivation")%>
                         </ItemsTemplate>:

and my code is looking for the control with ID SDeactivation for the combobox. How do I ensure It is looking for data checked from the checkbox?

Code:


 Protected Sub Button131_Click(ByVal sender As Object, ByVal e As EventArgs) Handles Button131.Click

        Dim str1 As String = Nothing
        xx = 0
        yy = 0
        zz = 0
        ww = 0
        Dim ctrlA As Control = MultiView1.FindControl("C1SDeactivation")
        For i = 0 To C1SDeactivation.Items.Count - 1
            If C1SDeactivation.Items(i).Selected Then
                MsgBox("Test") *****Does not execute
                If i = 0 Then
                    xx = 1
                End If
                If i = 1 Then
                    yy = 1
                End If
                If i = 2 Then
                    zz = 1
                End If
                If i = 3 Then
                    ww = 1
                End If
            End If
            MsgBox(i)
        Next
        MsgBox(xx)
        MsgBox(yy)
        MsgBox(zz)
        MsgBox(ww)
End Sub

Control:

<cc1:C1ComboBox ID="C1SDeactivation" runat="server"
                         OpenDropDownOnLoad="True"
                         SelectionMode="Multiple" Width="180px"    
                         onselectedindexchanged="C1SDeactivationA_SelectedIndexChanged"
                         OnClientSelectedIndexChanged ="C1SDeactivationA_OnClientSelectedIndexChanged"
                         AccessKey="" ToolTip="" HideDropDownListOnBlur="False"
                         DropDownPositioningMode="BottomCenter" DropDownHeight="100"
                         Text="Select (Multiple Allowed)" ShowTrigger="False" IsEditable="False">
                          <ItemsTemplate>
                            <asp:CheckBox ID="SDeactivation" runat="server" onChange="setColor(); " />
                             <%# DataBinder.Eval(Container.DataItem, "SDeactivation")%>
                         </ItemsTemplate>
                     </cc1:C1ComboBox>


Thanks,


Victor
⚡ FREE TRIAL OFFER
Try out a week of full access for free.
Find out why thousands trust the EE community with their toughest problems.
Nasir Razzaq

Have you stepped through the code? You have

Dim ctrlA As Control = MultiView1.FindControl("C1SDeactivation")
        For i = 0 To C1SDeactivation.Items.Count - 1
            If C1SDeactivation.Items(i).Selected Then

you are finding ctrlA but using name of the control

Try

Dim ctrlA As C1Combobox = MultiView1.FindControl("C1SDeactivation")
        For i = 0 To C1SDeactivation.Items.Count - 1
            If C1SDeactivation.Items(i).Selected Then
Victor Charles

ASKER
Hello,

I tried it but  "If C1SDeactivation.Items(i).Selected Then" still doesn't execute when I select the rows. Not certtain why use ctrlA since it is not used anywhere in the code, could that be the problem?
ASKER CERTIFIED SOLUTION
Nasir Razzaq

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
GET A PERSONALIZED SOLUTION
Ask your own question & get feedback from real experts
Find out why thousands trust the EE community with their toughest problems.
Victor Charles

ASKER
I'm afraid both approaches did not work, looking at an old project where it worked before but still can't figure it out will keep trying a get back to you. Thanks.
All of life is about relationships, and EE has made a viirtual community a real community. It lifts everyone's boat
William Peck