读书人

怎么遍历checklistbox里的已选中项

发布时间: 2012-02-13 17:20:26 作者: rapoo

如何遍历checklistbox里的已选中项
我想把每个一选中的项逐一添加到文本文件里,请问该如何写代码

[解决办法]
for i to list1.listcount-1
if list1.selected(i) then

end if
next
[解决办法]
前端:

<html xmlns= "http://www.w3.org/1999/xhtml " >
<head runat= "server ">
<title> Untitled Page </title>
</head>
<body>
<form id= "form1 " runat= "server ">
<div>
<asp:CheckBoxList ID= "CheckBoxList1 " runat= "server ">
<asp:ListItem Value= "aa "> </asp:ListItem>
<asp:ListItem Value= "bb "> </asp:ListItem>
<asp:ListItem Value= "cc "> </asp:ListItem>
<asp:ListItem Value= "dd "> </asp:ListItem>
</asp:CheckBoxList>
<asp:TextBox ID= "TextBox1 " runat= "server "> </asp:TextBox>
<asp:Button ID= "Button1 " runat= "server " OnClick= "Button1_Click " Text= "Button " /> </div>
</form>
</body>
</html>


后置代码里:


protected void Button1_Click(object sender, EventArgs e)
{
int i;
TextBox1.Text = " ";
for (i = 0; i < CheckBoxList1.Items.Count; i++)
{
if (CheckBoxList1.Items[i].Selected)
{
TextBox1.Text += CheckBoxList1.Items[i].Text;
}
}
}


读书人网 >VB Dotnet

热点推荐