日期:2014-05-18  浏览次数:20391 次

gridview翻页时能否不刷新?
我给GridView中的一列绑定了CheckBox,我选中了第1页中的CheckBox,翻页时如果刷新,翻到第2页时第1页选中的CheckBox就失效了,如果不刷新则无法显示第2页的记录,如何解决呢?

------解决方案--------------------
没有内置此项功能,

在执行翻页的时候,手动记录选中的项,翻回来的手动遍历,将状态恢复上去
------解决方案--------------------
要不刷新用AJAX
....
第一、第二等等页的CheckBox都选中??
------解决方案--------------------
用AJAX实现无刷新,
要想第一页被选中的CheckBox在翻页后还选中,其实也可以实现,
当选中了第一页的CheckBox后就记录被选中记录的标识,在翻页后就判断,
GridView中CheckBox的ID与保存的ID相同就被选中
------解决方案--------------------
private void dgrzkcxInfo_ItemDataBound(object sender, System.Web.UI.WebControls.DataGridItemEventArgs e)
{
if(e.Item.ItemType ==ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem)
{
e.Item.Attributes.Add( "onmouseover ", "ccolor=this.style.backgroundColor;this.style.backgroundColor= '#6699ff ' ");
e.Item.Attributes.Add( "onmouseout ", "this.style.backgroundColor=ccolor ");
if(txtList.Value.IndexOf(e.Item.Cells[1].Text)> =0)//main key
{
HtmlInputCheckBox check = (HtmlInputCheckBox)e.Item.Cells[0].FindControl( "chkSelect ");
check.Checked =true;

}
if(e.Item.Cells[5].Text != " " && e.Item.Cells[5].Text != "&nbsp ")
{
DateTime overtime =Convert.ToDateTime(DataBinder.Eval(e.Item.DataItem, "infoendtime ", "{0:yyyy-MM-dd} "));
if(overtime.AddDays(10) <=DateTime.Now)
{
e.Item.Cells[5].Text= "过期 ";
e.Item.Cells[5].ForeColor=Color.Red;
}
}
}
}


//////////////////////

<script language= "javascript ">
<!--
function add(ocheck)
{
if(ocheck.checked)
{
Form1.txtList.value+= ", "+ocheck.value;
}
else
{
Form1.txtList.value= Form1.txtList.value.replace( ", "+ocheck.value, " ");
}
}
//-->
</script>

<INPUT id= "txtList " style= "WIDTH: 192px; HEIGHT: 22px " readOnly type= "text " size= "26 " runat= "server ">
------解决方案--------------------
mark
------解决方案--------------------
翻页不刷新只能是用ajax!

翻页保持选择状态.用javascript应该可以!


<翻页保持选择状态> 这功能没做过!仅供参考.我没做过.