ListBox1控件

ListBox1控件

前台:

  <div>
<asp:ListBox ID="ListBox1" runat="server" AutoPostBack="True" Height="66px" OnSelectedIndexChanged="ListBox1_SelectedIndexChanged1" Width="80px">
<asp:ListItem></asp:ListItem>
<asp:ListItem></asp:ListItem>
<asp:ListItem></asp:ListItem>
<asp:ListItem></asp:ListItem>
</asp:ListBox>
<asp:Label ID="Label1" runat="server"></asp:Label>
</div>

后台

第一种foreach循环

protected void ListBox1_SelectedIndexChanged1(object sender, EventArgs e)
{ string strHobby = "";
foreach (ListItem item in ListBox1.Items)
{ if (item.Selected)
{
strHobby += item.Value + ""; }
} Label1.Text = strHobby;
}

for循环

    protected void ListBox1_SelectedIndexChanged1(object sender, EventArgs e)
{
string strHobby = "";
for (int i = ; i < ListBox1.Items.Count; i++)
{
if (ListBox1.Items[i].Selected)
{
strHobby += ListBox1.Items[i].Value ;
}
}
Label1.Text = strHobby;
}
上一篇:SolidWorks 装配体及工程图


下一篇:点击按钮显示隐藏DIV,点击DIV外面隐藏DIV