?
Solved

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

Posted on 2012-03-09
10
Medium Priority
?
348 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
Automating Terraform w Jenkins & AWS CodeCommit

How to configure Jenkins and CodeCommit to allow users to easily create and destroy infrastructure using Terraform code.

 

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 2000 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

What is SQL Server and how does it work?

The purpose of this paper is to provide you background on SQL Server. It’s your self-study guide for learning fundamentals. It includes both the history of SQL and its technical basics. Concepts and definitions will form the solid foundation of your future DBA expertise.

Question has a verified solution.

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

Just a quick little trick I learned recently.  Now that I'm using jQuery with abandon in my asp.net applications, I have grown tired of the following syntax:      (CODE) I suppose it just offends my sense of decency to put inline VBScript on a…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
Add bar graphs to Access queries using Unicode block characters. Graphs appear on every record in the color you want. Give life to numbers. Hopes this gives you ideas on visualizing your data in new ways ~ Create a calculated field in a query: …
This tutorial will teach you the special effect of super speed similar to the fictional character Wally West aka "The Flash" After Shake : http://www.videocopilot.net/presets/after_shake/ All lightning effects with instructions : http://www.mediaf…
Suggested Courses

770 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