【发布时间】:2012-10-23 18:17:59
【问题描述】:
我正在尝试将 asp.net(vs 2005/.net 2.0)中复选框列表中的选定项目作为连接字符串传递。
目前我的 .aspx 是
<asp:CheckBoxList id="checkbox1" AutoPostBack="False" AppendDataBoundItems="true" CellPadding="5" CellSpacing="5" RepeatColumns="1" RepeatDirection="Vertical" RepeatLayout="Flow" TextAlign="Right" runat="server">
<asp:ListItem Value="1">Carrots</asp:ListItem>
<asp:ListItem Value="2">Lettuce</asp:ListItem>
<asp:ListItem Value="3">Olives</asp:ListItem>
<asp:ListItem Value="4">Onions</asp:ListItem>
<asp:ListItem Value="5">Tomato</asp:ListItem>
<asp:ListItem Value="6">Pickles</asp:ListItem>
</asp:CheckBoxList>
而 .aspx.vb 是(在 Protected Sub 内提交)
For Each li As ListItem In checkbox1.Items
If li.Selected = True Then
checkbox1.Text = checkbox1.Text + "," + li.Text
End If
Next
通过
写入数据库checkbox1.Text = dv(0)("Salad").ToString()
当我选择并保存时,我目前遇到错误
“/”应用程序中的服务器错误。
'checkbox1' 有一个无效的 SelectedValue,因为它不存在于项目列表中。
参数名称:值
关于如何连接选中的复选框项目的任何想法
例如,如果有人选择胡萝卜、生菜和番茄;
checkbox1 = 1,2,5
【问题讨论】:
标签: asp.net vb.net .net-2.0 concatenation checkbox