在一个页面中拖一个GridView,建立了一个按钮列,命令是Edit,
protected void GridView1_RowEditing(object sender, GridViewEditEventArgs e)
    {
        string cardID = Convert.ToString(GridView1.DataKeys[e.NewEditIndex].Value);
        Response.Redirect("DetailInfo.aspx?cardID="+cardID+"");//传递ID列的值
    }
 取得此行记录ID列的值后,查看此行的详细信息,以下是DetailInfo.aspx页的Page_Load方法:
 protected void Page_Load(object sender, EventArgs e)
    {
        string cID = Request.QueryString["cardID"];
        DB db = new DB();//DB是自己写的数据库操作类
        SqlConnection con = db.createCon();
        con.Open();
        SqlCommand cmd=new SqlCommand("select * from customer where ID='" + cID + "'", con);
        SqlDataReader sdr = cmd.ExecuteReader();
        sdr.Read();
......后面代码省略,主要是让sdr中的数据在页面上显示出来
    }
但是当运行后我单击GridView1的已行时,在GridView1_RowEditing方法中的GridView1.DataKeys[e.NewEditIndex]这已句中出现一个异常,提示Index参数超出了集合的范围,记得我在另一个程序中这么用是可以的啊!
请高手指点~~~