Solved

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

Posted on 2012-03-09
10
347 Views
Last Modified: 2012-03-30
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
0
Comment
Question by:vcharles
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 5
  • 3
  • 2
10 Comments
 
LVL 83

Expert Comment

by:CodeCruiser
ID: 37703442
Its because the following condition

 If C1SDeactivation.Items(i).Selected Then

never evaluates to true.
0
 

Author Comment

by:vcharles
ID: 37703461
I know but I don't know why because I did select the rows when I clicked on the checkboxes.
0
 
LVL 7

Expert Comment

by:markmiddlemist
ID: 37703652
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)
0
MIM Survival Guide for Service Desk Managers

Major incidents can send mastered service desk processes into disorder. Systems and tools produce the data needed to resolve these incidents, but your challenge is getting that information to the right people fast. Check out the Survival Guide and begin bringing order to chaos.

 

Author Comment

by:vcharles
ID: 37703676
I'm afraid checked is not a propery of the combobox, how do I cast the control tyo checkbox?
Thanks.
0
 
LVL 7

Expert Comment

by:markmiddlemist
ID: 37703776
0
 

Author Comment

by:vcharles
ID: 37705494
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
0
 
LVL 83

Expert Comment

by:CodeCruiser
ID: 37705942
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
0
 

Author Comment

by:vcharles
ID: 37705994
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?
0
 
LVL 83

Accepted Solution

by:
CodeCruiser earned 500 total points
ID: 37706973
Yes that is the problem. I should have updated the rest of the code. So either

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

pr

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

Author Comment

by:vcharles
ID: 37707227
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.
0

Featured Post

On Demand Webinar: Networking for the Cloud Era

Did you know SD-WANs can improve network connectivity? Check out this webinar to learn how an SD-WAN simplified, one-click tool can help you migrate and manage data in the cloud.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Today I had a very interesting conundrum that had to get solved quickly. Needless to say, it wasn't resolved quickly because when we needed it we were very rushed, but as soon as the conference call was over and I took a step back I saw the correct …
Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
Michael from AdRem Software outlines event notifications and Automatic Corrective Actions in network monitoring. Automatic Corrective Actions are scripts, which can automatically run upon discovery of a certain undesirable condition in your network.…
Monitoring a network: how to monitor network services and why? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the philosophy behind service monitoring and why a handshake validation is critical in network monitoring. Software utilized …

688 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question