我想选中某一个的时候,显示他的text,可是我输出的怎么是vlaue呢?
Response.Write(CheckBoxList2.Text);
我想要的效果是选中了25-34岁,就输出25-34岁,如果选中了25-34岁和1000-3000元,就输出25-34岁和1000-3000元
//年龄
List<string[]> cblAge = new List<string[]>(); cblAge.Add(new string[] { "18岁以下", "37209" });
cblAge.Add(new string[] { "18-24岁", "160765" });
cblAge.Add(new string[] { "25-34岁", "492343" });
cblAge.Add(new string[] { "35-44岁", "542349" });
cblAge.Add(new string[] { "45岁以上", "307685" });
ListItem ltAge;
for (int i = 0; i < cblAge.Count; i++)
{
ltAge = new ListItem(cblAge[i][0], cblAge[i][1]);
ltAge.Attributes["text"] = cblAge[i][0];
ltAge.Attributes["value1"] = cblAge[i][1];
this.CheckBoxList2.Items.Add(ltAge);
} //月收入
List<string[]> cblMoney = new List<string[]>(); cblMoney.Add(new string[] { "1000元以下", "417209" });
cblMoney.Add(new string[] { "1000-3000元", "660765" });
cblMoney.Add(new string[] { "3000-5000元", "492343" });
cblMoney.Add(new string[] { "5000-10000元", "142349" });
cblMoney.Add(new string[] { "10000元以上", "107685" });
ListItem ltMoney;
for (int i = 0; i < cblMoney.Count; i++)
{
ltMoney = new ListItem(cblMoney[i][0], cblMoney[i][1]);
ltMoney.Attributes["text"] = cblMoney[i][0];
ltMoney.Attributes["value1"] = cblMoney[i][1];
this.CheckBoxList3.Items.Add(ltMoney);
}
Response.Write(CheckBoxList2.Text);
我想要的效果是选中了25-34岁,就输出25-34岁,如果选中了25-34岁和1000-3000元,就输出25-34岁和1000-3000元
//年龄
List<string[]> cblAge = new List<string[]>(); cblAge.Add(new string[] { "18岁以下", "37209" });
cblAge.Add(new string[] { "18-24岁", "160765" });
cblAge.Add(new string[] { "25-34岁", "492343" });
cblAge.Add(new string[] { "35-44岁", "542349" });
cblAge.Add(new string[] { "45岁以上", "307685" });
ListItem ltAge;
for (int i = 0; i < cblAge.Count; i++)
{
ltAge = new ListItem(cblAge[i][0], cblAge[i][1]);
ltAge.Attributes["text"] = cblAge[i][0];
ltAge.Attributes["value1"] = cblAge[i][1];
this.CheckBoxList2.Items.Add(ltAge);
} //月收入
List<string[]> cblMoney = new List<string[]>(); cblMoney.Add(new string[] { "1000元以下", "417209" });
cblMoney.Add(new string[] { "1000-3000元", "660765" });
cblMoney.Add(new string[] { "3000-5000元", "492343" });
cblMoney.Add(new string[] { "5000-10000元", "142349" });
cblMoney.Add(new string[] { "10000元以上", "107685" });
ListItem ltMoney;
for (int i = 0; i < cblMoney.Count; i++)
{
ltMoney = new ListItem(cblMoney[i][0], cblMoney[i][1]);
ltMoney.Attributes["text"] = cblMoney[i][0];
ltMoney.Attributes["value1"] = cblMoney[i][1];
this.CheckBoxList3.Items.Add(ltMoney);
}
CheckBoxList2.SelectedValue
然后写checkboxlist的selectindexchanged方法
如下,这样无论是单选还是多选都是可以的
protected void CheckBoxList2_SelectedIndexChanged(object sender, EventArgs e)
{
foreach (ListItem li in this.CheckBoxList2.Items)
{
if (li.Selected == true)
{
result += li.Text;
}
else
{
result = result.Replace(li.Text, "");
}
}
Response.Write(result);
}
如果你又专门的按钮也是可以的
不过循环遍历是必须的了。。
我觉得是你初始化时又问题
string Newsid = ""; foreach (RepeaterItem item in RepNewlist.Items)
{
HtmlInputCheckBox ch = (HtmlInputCheckBox)item.FindControl("checkboenewsid");
if (ch.Checked)
{
Newsid += "'" + ch.Value + "',";
} }
if (Newsid != "")
{
Newsid = Newsid.Substring(0, Newsid.Length - 1);
newsbll.DelNewsByIdAll(Newsid);
}
循环遍历