CheckBox在gridview中的 全选 事件 (怎么用js搞定)
怎么用js 取到gridview中生成的CheckBox的id 用document.什么对象(cbk_hckb)
全选的CheckBox 在页头 id 为(cbk_qckb)
gridview中生成的CheckBox id 为(cbk_hckb)
//服务器端全选事件
protected void CheckBox3_CheckedChanged(object sender, EventArgs e)
{ CheckBox chk;
foreach (DataGridItem dgi in DataGrid1.Items)
{
chk = (CheckBox)dgi.FindControl( "CheckBox1 ");
if (!chk.Checked)
{
chk.Checked = true;
}
else
{
chk.Checked = false;
}
}
}
谢谢 大概谈一下思路 小弟就够用了
[解决办法]
protected void CheckBox2_CheckedChanged(object sender, EventArgs e)
{
for (int i = 0; i <= GridView1.Rows.Count - 1; i++)
{
CheckBox cbox = (CheckBox)GridView1.Rows[i].FindControl( "CheckBox1 ");
if (CheckBox2.Checked == true)
{
cbox.Checked = true;
}
else
{
cbox.Checked = false;
}
}
}
[解决办法]
GridView 实现服务器端和客户端全选的两种方法
http://dotnet.aspx.cc/article/a8efc285-f0b1-4f8f-8e73-2b7d8724a47c/read.aspx
[解决办法]
第一行headertext中写: HeaderText= "<input type= 'checkbox ' name= 'chkAll ' onclick= 'ChkSelectAll(document.all.chkSelect, document.all.chkAll.checked); ' title= '全选或全不选 '>
<ItemTemplate> 中
<input type= "checkbox " name= "chkSelect " class= "list-checkbox ">
ChkSelectAll定义大致;
function ChkSelectAll(objCheck, ischecked)
{
var SelectedCount = 0;
if (!objCheck)
return SelectedCount;
if(objCheck[0])
{
l = objCheck.length;
for(var i=0;i <l;i++)
{
//objCheck[i].checked=ischecked;
if (objCheck[i].checked != ischecked)
{
objCheck[i].click();
}
if (objCheck[i].checked)
{
SelectedCount = SelectedCount + 1;
}
}
}
else
{
if(objCheck)
{
//objCheck.checked=ischecked;
if (objCheck.checked != ischecked)
{
objCheck.click();
}
if (objCheck.checked)
{
SelectedCount = SelectedCount + 1;
}
}
}
return SelectedCount;
}