GridView绑定数据后,Label1显示绑定数据库表中的ID,然后点击按钮,跳转另一页面,把这个Label1中保存的ID也传到另一页面Default.aspx.cs:public int myid;
 protected void Page_Load(object sender, EventArgs e)
    {
        SqlConnection con = new SqlConnection("Server=.;Uid=sa;DataBase=aaaaaa");
        string str = "Select top 10 * From bbb";        con.Open();
        DataSet ds = new DataSet();
        SqlDataAdapter da = new SqlDataAdapter(str, con);
        da.Fill(ds);        this.GridView1.DataSource = ds.Tables[0].DefaultView;
        this.GridView1.DataBind();   
     }
 protected void GridView1_RowCommand(object sender, GridViewCommandEventArgs e)
    {
        Label lab = (Label)this.dgvArrangeSongs.Rows[((GridViewRow)((LinkButton)e.CommandSource).NamingContainer).RowIndex].FindControl("lblID");
        myid = Int32.Parse(lab.Text);        if (e.CommandName == "aaa")
        {
           Response.Redirect("Default2.aspx?id='" + myid + "'");
        }
    }
Default2.aspx.cs:    protected void Page_Load(object sender, EventArgs e)
    {
        this.Label1.Text = Request.QueryString["myid"].ToString();
    }运行之后出现这个错误:回发或回调参数无效。在配置中使用 <pages enableEventValidation="true"/> 或在页面中使用 <%@ Page EnableEventValidation="true" %> 启用了事件验证。出于安全目的,此功能验证回发或回调事件的参数是否来源于最初呈现这些事件的服务器控件。如果数据有效并且是预期的,则使用 ClientScriptManager.RegisterForEventValidation 方法来注册回发或回调数据以进行验证。 请高手帮忙,在线等!

解决方案 »

  1.   

    这个问题我也遇见过,但忘记怎么解决的了
    google可以找到的
      

  2.   

    在page里修改这个属性
    <%@ Page enableEventValidation="false" ...    或者  在webconfig 里加上 <pages enableEventValidation="false" validateRequest="false">
      

  3.   

    public int myid; 
    protected void Page_Load(object sender, EventArgs e) 
        { 
            SqlConnection con = new SqlConnection("Server=.;Uid=sa;DataBase=aaaaaa"); 
            string str = "Select top 10 * From bbb";         con.Open(); 
            DataSet ds = new DataSet(); 
            SqlDataAdapter da = new SqlDataAdapter(str, con); 
            da.Fill(ds);         this.GridView1.DataSource = ds.Tables[0].DefaultView; 
            this.GridView1.DataBind();  
        } 
    protected void GridView1_RowCommand(object sender, GridViewCommandEventArgs e) 
        { 
            
            if (e.CommandName == "aaa") 
            { 
              GridViewRow gv = (GridViewRow)((Control)e.CommandSource).Parent.Parent;
              Label lab = (Label)this.dgvArrangeSongs.Rows[gv.RowIndex].FindControl("lblID"); 
              myid = Int32.Parse(lab.Text); 
              Response.Redirect("Default2.aspx?id='" + myid + "'"); 
            } 
        } 
    Default2.aspx.cs:     protected void Page_Load(object sender, EventArgs e) 
        { 
            this.Label1.Text = Request.QueryString["id"].ToString(); 
        } 
      

  4.   

    <%@ Page EnableEventValidation="false" %>
    4楼是高手啊~~
      

  5.   

    添加enableEventValidation="false" 
     Page_Load里加
    if (!Page.IsPostBack) 
    {
    //绑定数据 
    }