Solved

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

Posted on 2012-03-09
10
337 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
  • 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
 

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
IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

 

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

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

ASP.Net to Oracle Connectivity Recently I had to develop an ASP.NET application connecting to an Oracle database.As I am doing it first time ,I had to solve several problems. This article will help to such developers  to develop an ASP.NET client…
Many of us here at EE write code. Many of us write exceptional code; just as many of us write exception-prone code. As we all should know, exceptions are a mechanism for handling errors which are typically out of our control. From database errors, t…
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…
This video explains how to create simple products associated to Magento configurable product and offers fast way of their generation with Store Manager for Magento tool.

757 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

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now