C# .net
參考答案://删除
private void DataGrid1_DeleteCommand(object source, System.Web.UI.WebControls.DataGridCommandEventArgs e)
{
Label lblID = (Label)e.Item.FindControl("lblId");
//判断当前页是否为最后一页,且该页只有最后一条记录
if((DataGrid1.CurrentPageIndex==DataGrid1.PageCount-1) && DataGrid1.Items.Count==1)
{
//如果当前页-1>1表示当前页为多页的最后一页
if(DataGrid1.CurrentPageIndex-1>1)
{
//由于是多页中的最后一页,且是最后一条记录,会产生异常,此时将当前页手动减1,避免异常
DataGrid1.CurrentPageIndex = DataGrid1.CurrentPageIndex-1;
this.DDLPage.Items.RemoveAt(DDLPage.Items.Count-1);
this.lblDiJiPage.Text="当前是第 "+(DataGrid1.CurrentPageIndex+1)+" 页/共 "+DDLPage.Items.Count+" 页";
}
else
{
DataGrid1.CurrentPageIndex = 0;
this.DDLPage.Items.RemoveAt(DDLPage.Items.Count-1);//获得DropDownList集合的总数,减去集合中最大值
this.lblDiJiPage.Text="当前是第 "+DDLPage.Items.Count+" 页/共 "+DDLPage.Items.Count+" 页";
}
}
string sqlDel = "delete from DEALER_LEAVEWORD_TB where DEALER_ID='"+lblID.Text+"'";
ConnectSqlServer.doInsert(sqlDel);
this.Bind();
}
这段代码你考回去,就可以解决你的问题