Pergunta

Eu estou tentando executar o código abaixo a lista o item selecione em uma caixa de seleção

para o corpo do e-mail

 Dim CheckedValues As String
                For Each item In txt_panview0_ddinput1.Items
                    If item.checked Then
                        checkedValues = checkedValues & item.selectedValue

                    End If
                Next
                If Not String.IsNullOrEmpty(checkedValues) Then
                    checkedValues = checkedValues.Substring(1)
                End If


                tempCollector = tempCollector + "<br>" + "Area Name" + ": " + checkedValues

Mas eu estou recebendo o seguinte erro ..

System.MissingMemberException: Public member 'checked' on type 'ListItem' not found. 
at Microsoft.VisualBasic.CompilerServices.Symbols.Container.GetMembers(String& MemberName, 
Boolean ReportErrors) at Microsoft.VisualBasic.CompilerServices.NewLateBinding.
LateGet(Object Instance, Type Type, String MemberName, Object[] Arguments, String[] ArgumentNames, Type[] 
TypeArguments, Boolean[] CopyBack) at WebApplication1._Default.collectEmailBodyText() 
in C:\UseFormCode\UseFormEnhWorking\Default.aspx.vb:line 271 

Por favor, ajuda

Foi útil?

Solução

Typecast cada item na iteração a um CheckBox antes de verificar se ele é verificado:

For Each item In txt_panview0_ddinput1.Items
     dim c as CheckBox = Ctype(item.Value, CheckBox)
     If c.checked Then
         checkedValues = checkedValues & item.selectedValue
    End If
Next

Para ativar a seleção de vários valores, defina a propriedade SelectionMode do ListBox para Multiple:

<asp:ListBox ID="ListBox1" runat="server" SelectionMode="Multiple"></asp:ListBox>

Então, para repetir os valores selecionados, use o seguinte:

For Each item as ListItem In txt_panview0_ddinput1.Items
         If item.Selected Then
             CheckedValues = CheckedValues & item.Value
        End If
Next

PS Eu sou um enferrujado pouco sobre VB.Net sintaxe assim que meu código não pode ser sintaticamente perfeito

Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top