是这个问题吗?
If not IspostBack then
 ...
end if

解决方案 »

  1.   

    不是,是datagrid中删除数据后,页面的重载问题!!!
      

  2.   

    删除之后 重新帮定数据源
    MyDataGrid.DataSource="";   
    MyDataGrid.DataBind();
      

  3.   

    //删除当前记录
    private void DataGrid1_DeleteCommand(object source, System.Web.UI.WebControls.DataGridCommandEventArgs e)
    {
       //你的删除代码
       ...... 
       BindGrid();
    }
    //分页
    private void DataGrid1_PageIndexChanged(object source, System.Web.UI.WebControls.DataGridPageChangedEventArgs e)
    {
         DataGrid1.CurrentPageIndex = e.NewPageIndex;
         BindGrid();
    }
      

  4.   

    问题是要绑定当前页的数据,working1997(haha)说的和我一开始的想法一样,但是你说的:DataGrid1.CurrentPageIndex = e.NewPageIndex;
         BindGrid();
    写在哪里?如果写在del事件里,那e.newpageindex参数不对
      

  5.   

    pageload事件中:
    If not IspostBack then
     ...
    end if-----
    删除事件中:
    在删除动作完成后加入
    datagrid.databind()
    即可。----
    实现了,记得给分哦~~
      

  6.   

    我说过了,要实现当前页面的绑定,stevejobs的建议只能实现绑定,但是不能实现当前页面的绑定
      

  7.   

    删除之后重新绑定一次就可以了,
     DataGrid会自动到该页面。
      

  8.   

    删除之后重新绑定就可以了。datagrid的currentPageIndex不会变。
    但有一点要考虑,就是删除的纪录是当前页面的唯一条纪录(在最后一页),那么删除之后就会超出了页面数量的范围。应当将currentPageIndex设置为currentpageIndex-1或pageCount-1。
      

  9.   

    指定DataGrid的CurrentPageIndex属性后,重新绑定数据.
      

  10.   

    建议你可以看一看.net的帮助文档(好东西!),查找deletecommand 可以看到许多相关的示例.
    其中就有你想要的.
      

  11.   

    看一下我的这个,是成功的
    ===================================
    using System;
    using System.Collections;
    using System.ComponentModel;
    using System.Data;
    using System.Data.SqlClient;
    using System.Drawing;
    using System.Web;
    using System.Web.SessionState;
    using System.Web.UI;
    using System.Web.UI.WebControls;
    using System.Web.UI.HtmlControls;
    //using System.Windows.Forms;namespace AE.backend
    {
    /// <summary>
    /// index 的摘要说明。
    /// </summary>
    public class index : System.Web.UI.Page
    {
    protected System.Web.UI.WebControls.DataList DataList1;
    public System.Data.DataView dv;
    public int count_admin=0;
    private void Page_Load(object sender, System.EventArgs e)
    {
    if(Session["yn_sys_admin"].ToString().Equals("True"))
    {
    if (!Page.IsPostBack)
    {
    Conn.ConnClass dbconn=new Conn.ConnClass();
    DataSet da=new DataSet();
    da=dbconn.GetDs("select * from user_main","user");
    dv=da.Tables[0].DefaultView;
    DataList1.DataSource=dv;
    DataList1.DataBind();
    count_admin=dbconn.GetCountByTable("user_main");
    }
    }
    else
    {
    Response.Write("<script>window.alert('你没有管理权限!');window.location='../login/';</script>");
    }
    } #region Web 窗体设计器生成的代码
    override protected void OnInit(EventArgs e)
    {
    //
    // CODEGEN: 该调用是 ASP.NET Web 窗体设计器所必需的。
    //
    InitializeComponent();
    base.OnInit(e);
    }

    /// <summary>
    /// 设计器支持所需的方法 - 不要使用代码编辑器修改
    /// 此方法的内容。
    /// </summary>
    private void InitializeComponent()
    {    
    this.Load += new System.EventHandler(this.Page_Load); }
    #endregion

    public void BindList() 
    {
    Conn.ConnClass dbconn=new Conn.ConnClass();
    DataSet da=new DataSet();
    da=dbconn.GetDs("select * from user_main","user");
    DataList1.DataSource=da.Tables[0].DefaultView;
    DataList1.DataBind();
    count_admin=dbconn.GetCountByTable("user_main");
    }
    public void BindList1() 
    {
    DataList1.DataSource=dv;
    DataList1.DataBind();
    }
    public void DataList_ItemCommand(object Sender, DataListCommandEventArgs e) 
    {
    string cmd = ((LinkButton)e.CommandSource).CommandName;
    if (cmd == "detail")
    DataList1.SelectedIndex = e.Item.ItemIndex;
    else if(cmd == "cancel")
    DataList1.SelectedIndex = -1;
    else if(cmd == "insert")
    {
    int a,b,c,d;
    string usr=((TextBox)e.Item.FindControl("TextBox_usr")).Text;
    string realname=((TextBox)e.Item.FindControl("TextBox_realname")).Text;
    string pwd=((TextBox)e.Item.FindControl("TextBox_pwd_pre")).Text;
    bool yn_student=((CheckBox)e.Item.FindControl("CheckBox1_stu")).Checked;
    bool yn_teacher=((CheckBox)e.Item.FindControl("CheckBox2_tea")).Checked;
    bool yn_sys_admin=((CheckBox)e.Item.FindControl("CheckBox3_sys")).Checked;
    bool yn_news_admin=((CheckBox)e.Item.FindControl("CheckBox4_news")).Checked;
    if(yn_student)
    {
    a=1;
    }
    else
    {
    a=0;
    }
    if(yn_teacher)
    {
    b=1;
    }
    else
    {
    b=0;
    }
    if(yn_sys_admin)
    {
    c=1;
    }
    else
    {
    c=0;
    }
    if(yn_news_admin)
    {
    d=1;
    }
    else
    {
    d=0;
    }
    Conn.ConnClass connupdate=new Conn.ConnClass();
    connupdate.NonQuery("insert into user_main values ('"+usr+"','"+realname+"','"+pwd+"','"+a+"','"+b+"','"+c+"','"+d+"')");
    DataList1.SelectedIndex = -1;
    BindList();
    Response.Write("<script>window.alert('数据插入成功');</script>");
    }
    BindList();
    }
    public void DataList_EditCommand(Object Sender, DataListCommandEventArgs e) 
    {
    DataList1.EditItemIndex = (int)e.Item.ItemIndex;
    BindList();
    }
    public void DataList_CancelCommand(Object Sender, DataListCommandEventArgs e) 
    {
    DataList1.EditItemIndex = -1;
    BindList();
    }
    public void DataList_UpdateCommand(Object Sender, DataListCommandEventArgs e) 
    {
    int a,b,c,d;
    string pwd=((TextBox)e.Item.FindControl("TextBox_pwd")).Text;
    bool yn_student=((CheckBox)e.Item.FindControl("CheckBox_stu")).Checked;
    bool yn_teacher=((CheckBox)e.Item.FindControl("CheckBox_tea")).Checked;
    bool yn_sys_admin=((CheckBox)e.Item.FindControl("CheckBox_sys")).Checked;
    bool yn_news_admin=((CheckBox)e.Item.FindControl("CheckBox_news")).Checked;
    string id_str=((Label)e.Item.FindControl("Label1")).Text;
    if(yn_student)
    {
    a=1;
    }
    else
    {
    a=0;
    }
    if(yn_teacher)
    {
    b=1;
    }
    else
    {
    b=0;
    }
    if(yn_sys_admin)
    {
    c=1;
    }
    else
    {
    c=0;
    }
    if(yn_news_admin)
    {
    d=1;
    }
    else
    {
    d=0;
    }
    int id=System.Convert.ToInt32(id_str.ToString());
    Conn.ConnClass connupdate=new Conn.ConnClass();
    connupdate.NonQuery("update user_main set password='"+pwd+"',yn_student='"+a+"',yn_teacher='"+b+"',yn_sys_admin='"+c+"',yn_news_admin='"+d+"' where id ='"+id+"'");
    DataList1.EditItemIndex = -1;
    BindList();
    Response.Write("<script>window.alert('数据更新成功');</script>");
    }
    public void DataList_DeleteCommand(Object Sender, DataListCommandEventArgs e)
    {
    string id_str1=((Label)e.Item.FindControl("Label1")).Text;
    int id1=System.Convert.ToInt32(id_str1.ToString());
    Conn.ConnClass conndelete=new Conn.ConnClass();
    conndelete.NonQuery("delete from user_main where id='"+id1+"'");
    DataList1.EditItemIndex =-1;
    BindList();
    Response.Write("<script>window.alert('数据删除成功');</script>");
    }
    }
    }