日期:2014-05-20  浏览次数:20408 次

gridview全选问题
用checkbox做了一个gridview的全选框,可是只要一分页或排序所选中的记录就消失了,不知道如何解决该问题

------解决方案--------------------
session保存
------解决方案--------------------
你全选是怎么写的
1.要保持的话 必须注册CheckBox
CheckBox check = ((CheckBox)gvlDestination.theGridViewList.Rows[i].Cells[0].FindControl( "check "));
check.Checked = true;
if (check != null)
{
checkstr += string.Format( ";document.all[ '{0} '].checked=true ", check.ClientID);
}
}
JS.ExecuteBlock(this, checkstr);

------解决方案--------------------
试试这个

CheckBox cbx = (CheckBox)sender;
string checkstr;
foreach (GridViewRow gvr in gvComUnion.Rows)
{
CheckBox ch = (CheckBox)gvr.FindControl( "ItemCheckBox ");
//ch.Checked = cbx.Checked;
if (ch != null)
{
checkstr += string.Format( ";document.all[ '{0} '].checked=true ", ch.ClientID);
}
}
Page.RegisterStartupScript( "key1 ", string.Format( " <script> {0} </script> ",checkstr));