checkboxlist的selected值为何不改变? string strN = ""; for (int i = 0; i < chklstN.Items.Count; i++) { if (this.chklstN.Items[i].Selected) strN += chklstN.Items[i].Value+";"; }已经全部将复选框选中,并且AutoPostBack也设为了false,但循环中的每一个this.chklstN.Items[i].Selected都为false,不知是什么原因? 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 if (this.chklstN.Items[i].Checked) 可checkboxlist的Items[i]无Checked属性 if (this.checkedListBox1.CheckedItems.Count > 0) { foreach (string item in this.checkedListBox1.CheckedItems) { …………………… } } …………搞错了!是WEB的!哎 楼主 在.net里 按个.看看出来的属性,一般问题都可解决 代码放在确定按钮的click事件中: protected void btnOk_Click(object sender, ImageClickEventArgs e) { string strN = ""; for (int i = 0; i< chklstN.Items.Count; i++) { if (this.chklstN.Items[i].Selected) strN += chklstN.Items[i].Value+";"; } ... ... } protected void Page_Load(object sender, EventArgs e) { if (!Page.IsPostBack) { this.CheckBoxList1.Items.Add("vv"); this.CheckBoxList1.Items.Add("ss"); this.CheckBoxList1.Items.Add("mm"); } for (int i = 0; i < this.CheckBoxList1.Items.Count; i++) { this.CheckBoxList1.Items[i].Selected = true; } } protected void Button1_Click(object sender, EventArgs e) { for (int i = 0; i < this.CheckBoxList1.Items.Count; i++) { if (this.CheckBoxList1.Items[i].Selected) { string ss = ""; ss += this.CheckBoxList1.Items[i].Value; Response.Write(ss); } } } 以解决问题了原因:checkboxlist的item的加载是在page_load中在page_load()中忘了做if (!IsPostBack)的判断了... if(!ispostback){checkboxlist绑定}就可以了 关于dotras这个类库连接vpn问题。跪求,急用。 winform 如何自己画出平滑线条 循环取值 如何读取并更改这样的XML? 请高手救火 WPF适合初学者学习吗? 为什么Dreamweaver2004里asp.net c# 站点连不上access数据库啊 请大家帮我解决一下这个问题 listBox的SelectedIndexChanged事件没反应 如何不用DNS获取本机的IP地址? 腾讯讨论组的图片 关于format和AppendFormat C#.NET中 水晶报表自定义纸张问题!
{
foreach (string item in this.checkedListBox1.CheckedItems)
{
……………………
}
}
楼主 在.net里 按个.看看出来的属性,一般问题都可解决
protected void btnOk_Click(object sender, ImageClickEventArgs e)
{
string strN = "";
for (int i = 0; i< chklstN.Items.Count; i++)
{
if (this.chklstN.Items[i].Selected)
strN += chklstN.Items[i].Value+";";
}
... ...
}
{
if (!Page.IsPostBack)
{
this.CheckBoxList1.Items.Add("vv");
this.CheckBoxList1.Items.Add("ss");
this.CheckBoxList1.Items.Add("mm");
}
for (int i = 0; i < this.CheckBoxList1.Items.Count; i++)
{
this.CheckBoxList1.Items[i].Selected = true;
} }
protected void Button1_Click(object sender, EventArgs e)
{
for (int i = 0; i < this.CheckBoxList1.Items.Count; i++)
{
if (this.CheckBoxList1.Items[i].Selected)
{
string ss = "";
ss += this.CheckBoxList1.Items[i].Value;
Response.Write(ss);
}
}
}
原因:checkboxlist的item的加载是在page_load中
在page_load()中忘了做if (!IsPostBack)的判断了...
{
checkboxlist绑定
}
就可以了