首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > .NET > VB Dotnet >

怎么遍历checklistbox里的已选中项

2012-02-13 
如何遍历checklistbox里的已选中项我想把每个一选中的项逐一添加到文本文件里,请问该如何写代码[解决办法]

如何遍历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;
}
}
}


热点排行