DataGrid中的CheckBox,能不能不用循环检测的办法来得知是哪一个checkbox被选?
我的datagrid中的一列是checkbox对象。能不能不用遍历的办法就取得被选的哪个checkbox的itemindex?请各路大虾指教。 问题点数:20、回复次数:3Top
1 楼blacat27(春)回复于 2002-11-16 23:18:10 得分 20
这样的例子有很多了,你用搜索,关键字为:datagrid,或者checkbox
for (int i=0; i < dgfuList.Items.Count; i++)
{
CheckBox Remove = (CheckBox) dgfuList.Items[i].FindControl("Remove");
CheckBox PowerAllot = (CheckBox) dgfuList.Items[i].FindControl("PowerAllot");
if (Remove.Checked ==true) //if (ckbids.Checked == true || ckbids.Checked==false)
{
int intcheck=0;
if ( PowerAllot.Checked==true)
{
intcheck=1;
}
Label lblId = (Label) dgfuList.Items[i].FindControl("lblId");
}Top
2 楼zmjrose()回复于 2002-11-17 15:15:44 得分 0
我要得到刚被用户选中或取消选择的哪个checkbox的位置。Top
3 楼mmkk()回复于 2002-11-17 16:28:51 得分 0
如果需要分页并且要保持任意页被选中CheckBox的状态,我不知道还有没有更好的办法,这个我做的够呛,我的做法是:为这个CheckBox增加一个客户端的方法,可以通过ItemDataBound来完成(而且我认为最好是使用HtmlInputCheckBox);然后这个客户端的函数就是用来再另一个隐藏的控件中记录每个被选中的HtmlInputCheckBox,可以用特殊符号分开,比如逗号,最好还是在ItemDataBound中取得这个隐藏的控件发过来的数据,可以通过Request.Form["ControlId"]来取得,然后用Split()方法来分割,遍历检索,如果找到就Checked,hope helps!~Top




