CheckedListBox的读取Value值问题

yan1617 2004-01-19 10:57:34
判断CheckedListBox中选中的项的Value是true还是false
...全文
145 3 打赏 收藏 转发到动态 举报
写回复
用AI写文章
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
rottenapple 2004-01-19
  • 打赏
  • 举报
回复
checkboxlist1.Items[i].Selected
reformer 2004-01-19
  • 打赏
  • 举报
回复
1 如果只是显示当前选中的项目:

int k = this.checkedListBox1.SelectedIndex;
string msg = this.checkedListBox1.GetItemCheckState(k).ToString();
MessageBox.Show(msg.ToString());

2 返回当前Checked的所有项目

string msg = "";
foreach(object checkeditem in this.checkedListBox1.CheckedItems)
{
msg += checkeditem.ToString() + " ";
}
MessageBox.Show(msg.ToString());



shenanigan 2004-01-19
  • 打赏
  • 举报
回复
<%@ Page Language="C#" %>
<html>
<head>

<script language="C#" runat="server">

void Check_Clicked(Object sender, EventArgs e)
{
Message.Text = "Selected Item(s):<br><br>";
for (int i=0; i<checkboxlist1.Items.Count; i++)
{
if (checkboxlist1.Items[i].Selected)
Message.Text += checkboxlist1.Items[i].Text + "<br>";
}
}

</script>

</head>
<body>

<form action="checkboxlist.aspx" method="post" runat="server">

<h3>CheckBoxList Example</h3>

<asp:CheckBoxList id="checkboxlist1"
AutoPostBack="True"
CellPadding="5"
CellSpacing="5"
RepeatColumns="2"
RepeatDirection="Vertical"
RepeatLayout="Flow"
TextAlign="Right"
OnSelectedIndexChanged="Check_Clicked"
runat="server">

<asp:ListItem>Item 1</asp:ListItem>
<asp:ListItem>Item 2</asp:ListItem>
<asp:ListItem>Item 3</asp:ListItem>
<asp:ListItem>Item 4</asp:ListItem>
<asp:ListItem>Item 5</asp:ListItem>
<asp:ListItem>Item 6</asp:ListItem>

</asp:CheckBoxList>

<br><br>

<asp:label id="Message" runat="server"/>

</form>

</body>
</html>

110,536

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Web++
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧