foreach (GridViewRow gvr in thisgvMemberRows){if (((CheckBox)gvrFindControl("CheckBox1"))Checked) shopperIDListAdd(ConvertToInt64(thisgvMemberDataKeys[gvrRowIndex]Value));}// 请注意这个属性 gvMemberDataKeys 你可以在工具的属性栏目中找到它,代表着自定义主键集合,可以多个,用英文输入法状态时的逗号隔开,只有一个字段时,直接用thisgvMemberDataKeys[gvrRowIndex]Value就可以取得了,如果有多个字段,则使用thisgvMemberDataKeys[gvrRowIndex]Values[index]来获取
怎么获取checkbox的dafaultvaluevalue
首先用documentgetElementsByName()这个方法,通过input标签的name属性将input元素获取,并存进obj这个变量值中。
然后建一个check_val的数组,通过for循环将input标签的value值存入数组中,这样就可以获取checkbox的选中的多个值。
扩展资料:
您可以通过遍历表单的 elements[] 数组来访问某个选择框,或者通过使用 documentgetElementById() 。
用 raize控件好了 RzCheckGroup控件
var
i:integer;
Str:String;
begin
Str:='';
for i:=0 to RzCheckGroup1ItemsCount-1 do
begin
if RzCheckGroup1ItemChecked[i] then
str:=str+RzCheckGroup1ItemsStrings[i];
end;
showmessage(str);
end;
如果不用raize
那就定义checkbox的名字 依次为 checkBox1 checkBox2 checkBox3 checkBox4
var
i:integer;
Str:String;
begin
Str:='';
for i:=1 to 4 do
begin
if TCheckBox(FindComponent('checkBox'+inttostr(i)))Checked then
str:=str+TCheckBox(FindComponent('checkBox'+inttostr(i)))Caption;
end;
showmessage(str);
end;
<body>
<input type="checkbox" id="a" value="1" />1 <br />
<input type="checkbox" id="a" value="2" />2 <br />
<input type="checkbox" id="a" value="3" />3 <br />
<input type="checkbox" id="a" value="4" />4 <br />
<input type="button" onclick="checkBtn()" value="获取复选框选择的值" />
</body>
<script>
function checkBtn() {
$(":checked")each(function(i){
alert($(this)val());
});
}
</script>
public partial class Form1 : Form
{
//声明为全局变量
List<CheckBox> chks = new List<CheckBox>();
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
//调用示例
FindChks(this);
foreach (CheckBox c in chks)
MessageBoxShow(stringFormat(
"Name={0}, Text={1}", cName, cText));
}
//递归查找
void FindChks(Control c)
{
if (cHasChildren)
foreach (Control cc in cControls)
FindChks(cc);
else if (c is CheckBox)
chksAdd(c as CheckBox);
}
}
1:要看你是否把checkbox设置为服务器控件,如果设置为服务器控件,就可以在cs文件中编写foreach循环,遍历Control控件,判断是否为checkbox。
2:如果不设置为服务器端控件,则需使用js判断。
foreach (Control control in thisFormControls)
{
if (control is stemWebUIWebControlsTextBox) {
TextBox txt = (TextBox)control; txtText = "fdsafds";// stringEmpty;
}
}
这是Textbox的代码,原理与Checkbox相同,自己琢磨下吧。
function check() {
var x = 0;
var cblist = documentgetElementsByName("checkbox");
for (i = 0; i < cblistlength; i++) {
if (cblist[i]checked) {
x++;
}
}
if (x > 1) {
alert("只能选择单条数据");
}
else if (x == 1) {
alert("是否对选中数据进行 *** 作");
}
}
DataList里要用HTML的checkbox,不能用NET的
<input name="checkbox" type="checkbox" />
如果你非要用NET的CheckBox,把
var cblist = documentgetElementsByName("checkbox");
改成
var table = documentgetElementById("DataList1");
var cblist = table getElementsByTargetName("input");
不过这样如果你的DaleList模板里有TextBox或Button可能会有问题
思路:利用name属性值获取checkbox对象,然后循环判断checked属性(true表示被选中,false表示未选中)。
1、HTML结构
<input type="checkbox" name="test" value="1"/><span>1</span>
<input type="checkbox" name="test" value="2"/><span>2</span>
<input type="checkbox" name="test" value="3"/><span>3</span>
<input type="checkbox" name="test" value="4"/><span>4</span>
<input type="checkbox" name="test" value="5"/><span>5</span>
<input type='button' value='提交' onclick="show()"/>
2、javascript代码:
function show(){
obj = documentgetElementsByName("test");
check_val = [];
for(k in obj){
if(obj[k]checked)
check_valpush(obj[k]value);
}
alert(check_val);
}
扩展资料
jQuery对checkbox的各种 *** 作:
1、根据id获取checkbox:
$("#cbCheckbox1");
2、获取所有的checkbox:
$("input[type='checkbox']");//or
$("input[name='cb']");
3、获取所有选中的checkbox:
$("input:checkbox:checked");//or
$("input:[type='checkbox']:checked");//or
$("input[type='checkbox']:checked");//or
$("input:[name='ck']:checked");
以上就是关于怎么遍历并获取GridView中checkBox是否选中以及该项的id求解全部的内容,包括:怎么遍历并获取GridView中checkBox是否选中以及该项的id求解、怎么获取checkbox的dafaultvaluevalue、Delphi怎么遍历Groupbox中4个Checkbox哪个选中,并取得他们的Caption值等相关内容解答,如果想了解更多相关内容,可以关注我们,你们的支持是我们更新的动力!
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)