in the case,first you assure the data is preserved. i reserve the grid data in the session. so when i retrieve the grid,i will operation the session. List the follwing steps: DataTable dt = (datatable)session[yoursessionString]; foreach(DataRow dr in dt.rows) { //your code }
{
dataGrid.CurrentPageIndes=i;
for(int i=0;i<dataGird.Itsm.count;i++)
{
........
}
}
可老板叫我那么做,没办法,
wuzhijie()的方法我做过,行不通的
{
this.GetChecked();
this.DataGrid1.CurrentPageIndex=e.NewPageIndex;
this.BindGrid();//执行数据绑定的语句
}
2.在GetChecked方法里
{
if(object(ViewState["check"],null))
ArrayList my=(AraayList)ViewState["check"];
for(int i=0;i<dataGird.Itsm.count;i++)
{
........
if(checked)
my.Add(主键值);
}
}
3.数据绑定的语句别忘了设置datakeyfiled,因为在viewstate里保存的是datakey的列表,到用的时候也是根据这个最后的用的时候根据自己的需要来增删,比如你可以回退到上面的页,而根据viewstate里面保存的值显示出已被选中的列,进行显示、更改等,或者有按纽触发处理事件时,也要先执行GetChecked事件,把本页中选中的也加进去,等等原理大概如此,自己写吧
2.在GetChecked方法里
{
ArrayList my=null;
if(object(ViewState["check"],null))
my=(AraayList)ViewState["check"];
else my=new ArrayList();
for(int i=0;i<dataGird.Itsm.count;i++)
{
........
if(checked)
my.Add(主键值);
}
ViewState["check"]=my;
}
private void GetChecked()
{
ArrayList my=null;
if(!object.Equals(ViewState["check"],null))
my=(ArrayList)ViewState["check"];
else my=new ArrayList();
foreach(DataGridItem li in this.DataGrid1.Items)
{
CheckBox cb1=(CheckBox)li.FindControl("CheckBox1");
if(cb1.Checked&&!my.Contains(this.DataGrid1.DataKeys[li.ItemIndex]))
{
my.Add(this.DataGrid1.DataKeys[li.ItemIndex]);
}
if((!cb1.Checked)&&my.Contains(this.DataGrid1.DataKeys[li.ItemIndex]))
{
my.Remove(this.DataGrid1.DataKeys[li.ItemIndex]);
}
}
ViewState["check"]=my;
}
private void DataGrid1_PageIndexChanged(object source, System.Web.UI.WebControls.DataGridPageChangedEventArgs e)
{
this.GetChecked();
this.DataGrid1.CurrentPageIndex=e.NewPageIndex;
this.BindGrid();
}
private void DataGrid1_ItemDataBound(object sender, System.Web.UI.WebControls.DataGridItemEventArgs e)
{
if(e.Item.ItemType==ListItemType.Item||e.Item.ItemType==ListItemType.AlternatingItem)
{
ArrayList al=(ArrayList)ViewState["check"];
if(al!=null&&al.Contains(this.DataGrid1.DataKeys[e.Item.ItemIndex]))
{
CheckBox cb=(CheckBox)e.Item.FindControl("CheckBox1");
cb.Checked=true;
}
}
}
i reserve the grid data in the session.
so when i retrieve the grid,i will operation the session.
List the follwing steps:
DataTable dt = (datatable)session[yoursessionString];
foreach(DataRow dr in dt.rows)
{
//your code
}