java后台获取多个checkBox的选中状态。

java后台获取多个checkBox的选中状态。,第1张

怎么会不知道呢,每个给一个不同的值,获取的值,不就知道了么

当然,值要是重复的话,就不太好办了

那样的话,就做下处理,每个做个不同的id用js拼接,赋值隐藏域,后台处理下,也可以定位

解决方法

所以最好是修改jquerydatatable控件,给生成的每个datatable下的checkbox赋 予不同的id,因为datatable的id是不一样的,所以可以把 datatable的id作为 checkbox的前缀组成一个唯一的id 。 具体这个checkbox的调用事件也需要同步 替换成这个新id,进行事件的调用。

[修改文件]

jqureydatatableextjs (v001)

可以考虑把那些checkbox放在一个panel或者一个数组里,比如

foreach(Control

c

in

thisControls)

{

if

(c

is

CheckBox)

{

CheckBox

chk

=

(CheckBox)c;

chkChecked;

chkText;

}

}

这是我之前解决这个问题写的东西,直接贴上来,你看下吧。

private

List<Boolean>

originalFoundedDevicesState;

//有一个保存状态的list

给listview绑定adapter:

private

CheckAdapter

foundedDevices;

private

ListView

foundedList;

foundedDevices=new

CheckAdapter(AddingDevicesActthis,originalFoundedDevices,originalFoundedDevicesState);

foundedListsetAdapter(foundedDevices);

foundedListsetItemsCanFocus(false);foundedListsetChoiceMode(ListViewCHOICE_MODE_MULTIPLE);

foundedListsetOnItemClickListener(new

OnItemClickListener(){

public

void

onItemClick(AdapterView<>

parent,

View

view,

int

position,

long

id)

{

//

TODO

Auto-generated

method

stub

}

});

2自己为checkbox复写个adapter:

class

CheckAdapter

extends

BaseAdapter{

Context

mContext;

List<Device>

mData;

List<Boolean>status;

LayoutInflater

mInflater;

CheckBox

checkBox;

HashMap<Integer,View>

lmap=new

HashMap<Integer,View>();

public

CheckAdapter(Context

context,List<Device>

data,List<Boolean>

DeviceStatus)

{

mInflater=LayoutInflaterfrom(context);

mData=data;

status=DeviceStatus;

}

public

int

getCount()

{

//

TODO

Auto-generated

method

stub

return

mDatasize();

}

public

Object

getItem(int

position)

{

//

TODO

Auto-generated

method

stub

return

mDataget(position);

}

public

long

getItemId(int

position)

{

//

TODO

Auto-generated

method

stub

return

position;

}

public

View

getView(final

int

position,

View

convertView,

ViewGroup

parent)

{

//

TODO

Auto-generated

method

stub

if(lmapget(position)==null)

{

convertView=mInflaterinflate(Rlayoutchild,parent,

false);

checkBox=(CheckBox)convertViewfindViewById(Riddevices);

convertViewsetTag(checkBox);

}

else

{

checkBox=(CheckBox)convertViewgetTag();

}

checkBoxsetId(position);

checkBoxsetChecked(statusget(position));

checkBoxsetText(mDataget(position)toString());

checkBoxsetOnCheckedChangeListener(new

OnCheckedChangeListener(){

public

void

onCheckedChanged(CompoundButton

buttonView,

boolean

isChecked)

{

//

TODO

Auto-generated

method

stub

statusset(buttonViewgetId(),

isChecked);

notifyDataSetChanged();

}

});

return

convertView;

}

3最后可以根据其是否被选中状态判断某项是否被选中,并提取id:

for(num1=0;num1<originalFoundedDevicesStatesize();num1++)

{

if(originalFoundedDevicesStateget(num1))

finalPairedDevicesadd(new

Device(originalFoundedDevicesget(num1)getName(),

originalFoundedDevicesget(num1)getAddress()));

}

1:使用requestgetParameterValues(keyName)获取checkbox、select值;

在使用过程,如果select使用id标识,而不是name,则getParameterValues返回“”。

2:客户端控件在服务器端不能获取。必须加上runat="server"。

if(Checkboxchecked==true)

{

//选中状态

}

else

{

//未选中状态

}

只有这种方式,不加runat="server",后台无法获取。

在服务器中获取客户端的值必须让其变成服务器端控件。

在客户端即可获取客户端控件的值,也可获取服务器端控件的值,说白了说是脚本。

3:if (ckSysChecked == true)

{

userLimitLevel = thisckSysText;

}

if (ckBasicChecked == true)

{

userLimitLevel = thisckBasicText;

}

if (ckInforChecked == true)

{

userLimitLevel = thisckInforText;

}

if (ckTableChecked == true)

{

userLimitLevel = thisckTableText;

}

自己试试吧

以上就是关于java后台获取多个checkBox的选中状态。全部的内容,包括:java后台获取多个checkBox的选中状态。、DataTable表格如何获取不同分页的checkbox的状态、如何获取若干个动态生成的checkbox选中状态和它的文本值等相关内容解答,如果想了解更多相关内容,可以关注我们,你们的支持是我们更新的动力!

欢迎分享,转载请注明来源:内存溢出

原文地址:https://54852.com/web/9658362.html

(0)
打赏 微信扫一扫微信扫一扫 支付宝扫一扫支付宝扫一扫
上一篇 2023-04-30
下一篇2023-04-30

发表评论

登录后才能评论

评论列表(0条)

    保存