你的自动生成的代码添加到什么地方了?要放到和你的databind在一起的地方。因为每次页面一刷新,你new的button就没有了!所以每次load都要重新new一次。如果有一些特殊信息,可以放到viewstate里面保存处理。void page_load{
datagrid1.DataBind();
Button Del_Button = new Button()
Del_Button.Click += new System.EventHandler(this.Del_Button_Click);
.....
Del_Button_Click()
}
datagrid1.DataBind();
Button Del_Button = new Button()
Del_Button.Click += new System.EventHandler(this.Del_Button_Click);
.....
Del_Button_Click()
}
另外ViewState该怎么保存HtmlTable呢,又该怎么把他转换出来使用?
{
string sql="delete from t_CarMemorabilia where iId is null ";
int j=0;
foreach(DataGridItem dgi in DataGrid1.Items)
{
CheckBox cb=(CheckBox)(dgi.Cells[0].Controls[1]);
if (cb.Checked==true)
{
j+=1;
int i=dgi.ItemIndex;
int Id=Convert.ToInt32(DataGrid1.DataKeys[i].ToString());
sql+=" or iId="+Id;
}
}
try
{
publicClass.DataBase.ModifyData(sql);
}
catch
{
publicClass.ShowDialog("有错误发生!",this);
} if(DataGrid1.CurrentPageIndex!=0)
{
if(DataGrid1.Items.Count==j)
{
DataGrid1.CurrentPageIndex-=1;
}
}
BindGrid();
}