如何判断CheckBoxList中SelectedIndexChanged事件是哪个checkbox引发的 如何判断CheckBoxList中SelectedIndexChanged事件是哪个checkbox引发的请给出完整代码 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 private void checkedListBox1_SelectedIndexChanged(object sender, System.EventArgs e) { this.label1.Text=this.checkedListBox1.SelectedIndex.ToString(); } 拜托 pc_csharp(帮助别人,帮助自己) 回答问题要用脑 拜托 youkai(加肥猫) ( ) :对待别人的帮助要礼貌! private void checkedListBox1_SelectedIndexChanged(object sender, System.EventArgs e) { this.label1.Text=this.checkedListBox1.SelectedIndex.ToString(); } 下面返回所选项的Textthis.checkedListBox1.SelectedItem.ToString();下面返回所选项的Indexthis.checkedListBox1.SelectedIndex 说明一下,一、此问题出在b/s情况下所以,whxleem(feeling) 的方法行不通二、SelectedIndex方法取的是checkbox组中id最小的那个值 我想重要的是得到选中的项而不是得到哪个CheckBox触发PostBack的吧,如下方法得到选中的项Response.Write("选中项的值:<br>");foreach(ListItem li in ((CheckBoxList)sender).Items){if(li.Selected){Response.Write(li.Value+"<br>");}}如果非要得到触发的控件,可以这么做Response.Write("您刚才选中的项的ClientID是:"+Request.Form.AllKeys[Page.Request.Form.AllKeys.Length-1]+"<br>"); (以上代码写在private void CheckBoxList1_SelectedIndexChanged(object sender, System.EventArgs e){}中) 已经实现了,当方法很笨,大家看看还有没有其他方法 private static bool[] arrtmp; private void Page_Load(object sender, System.EventArgs e) { // 在此处放置用户代码以初始化页面 if(!IsPostBack) { arrtmp=new bool[CheckBoxList1.Items.Count]; for(int i=0;i <=CheckBoxList1.Items.Count-1;i++) { arrtmp[i]=CheckBoxList1.Items[i].Selected; } } } private void CheckBoxList1_SelectedIndexChanged(object sender, System.EventArgs e) { int clicknum; clicknum=-1; for(int i=0;i <= CheckBoxList1.Items.Count-1;i++) { if(arrtmp[i]!=CheckBoxList1.Items[i].Selected) { arrtmp[i] =CheckBoxList1.Items[i].Selected; clicknum=i; break; } } if(clicknum>=0) { TextBox1.Text=CheckBoxList1.Items[clicknum].ToString(); } } if判断 难难难!~~关于GDI+的问题,高手请进啊。急急急。。。 C/S模式中windows客户端和服务器端通信问题 异常:操作必须使用一个可更新的查询 关于字段和函数一起绑定问题,问题解决马上给分!急救! 局域网里,知道了IP地址,怎么获得主机名呀,求助!拜谢! 100M以上的大容量DataSet打开速度如何优化? 如何用C#开发自己的邮件转换系统? 一个非常头痛的问题,请大家来探讨一下 都说会 C++ 后再学 C# 容易得多 , 请问到底有多少 ? 关于矩阵计算为什么要进行normalize()? 求教C#实现FTP上传的解决方法(最后100分)
{
this.label1.Text=this.checkedListBox1.SelectedIndex.ToString();
}
回答问题要用脑
对待别人的帮助要礼貌!
{
this.label1.Text=this.checkedListBox1.SelectedIndex.ToString();
}
this.checkedListBox1.SelectedItem.ToString();下面返回所选项的Index
this.checkedListBox1.SelectedIndex
一、此问题出在b/s情况下所以,whxleem(feeling) 的方法行不通
二、SelectedIndex方法取的是checkbox组中id最小的那个值
Response.Write("选中项的值:<br>");
foreach(ListItem li in ((CheckBoxList)sender).Items)
{
if(li.Selected)
{
Response.Write(li.Value+"<br>");
}
}
如果非要得到触发的控件,可以这么做
Response.Write("您刚才选中的项的ClientID是:"+Request.Form.AllKeys[Page.Request.Form.AllKeys.Length-1]+"<br>");
private static bool[] arrtmp;
private void Page_Load(object sender, System.EventArgs e)
{
// 在此处放置用户代码以初始化页面
if(!IsPostBack)
{
arrtmp=new bool[CheckBoxList1.Items.Count];
for(int i=0;i <=CheckBoxList1.Items.Count-1;i++)
{
arrtmp[i]=CheckBoxList1.Items[i].Selected;
}
}
}
private void CheckBoxList1_SelectedIndexChanged(object sender, System.EventArgs e)
{
int clicknum; clicknum=-1;
for(int i=0;i <= CheckBoxList1.Items.Count-1;i++)
{
if(arrtmp[i]!=CheckBoxList1.Items[i].Selected)
{
arrtmp[i] =CheckBoxList1.Items[i].Selected;
clicknum=i;
break;
}
}
if(clicknum>=0)
{
TextBox1.Text=CheckBoxList1.Items[clicknum].ToString();
} }