尝试从复选框中检索数据时出现问题

时间:2009-07-30 14:13:14

标签: asp.net vb.net checkbox

我正在尝试执行以下代码,以在复选框中列出选择项

到邮件正文

 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

但我收到以下错误..

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 

请帮忙

1 个答案:

答案 0 :(得分:1)

在检查是否已检查之前,将迭代中的每个项目交叉到CheckBox

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

<击>

要启用多个值的选择,请将SelectionMode的{​​{1}}属性设置为ListBox

Multiple

然后迭代选定的值,使用以下内容:

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

PS我在VB.Net语法上有点生疏,所以我的代码可能在语法上不完美