asp.net中
<asp:GridView ID="GridView1"  runat="server" BackColor="White" BorderColor="#CC9966" BorderStyle="None" BorderWidth="1px" CellPadding="4"  AllowPaging="True" AutoGenerateColumns="False"   PageSize="20" OnPageIndexChanging="GridView1_PageIndexChanging" OnRowEditing="GridView1_RowEditing" OnRowUpdating="GridView1_RowUpdating"   OnRowCancelingEdit="GridView1_RowCancelingEdit" DataKeyNames="UserID,UserName,power,allow,CreatDate" OnRowDeleting="GridView1_RowDeleting" >
            <FooterStyle BackColor="#FFFFCC" ForeColor="#330099" />
            <RowStyle BackColor="White" ForeColor="#330099" />
            <PagerStyle BackColor="#FFFFCC" ForeColor="#330099" HorizontalAlign="Center" />
            <SelectedRowStyle BackColor="#FFCC66" Font-Bold="True" ForeColor="#663399" />
            <HeaderStyle BackColor="#990000" Font-Bold="True" ForeColor="#FFFFCC" />
            <Columns>
            <asp:BoundField DataField="UserID" HeaderText="用户ID"  />
                <asp:BoundField DataField="UserName" HeaderText="用户" />
                <asp:BoundField ReadOnly="true" DataField="lastDate" HeaderText="最近一次登陆时间" />
                <asp:BoundField DataField="power" HeaderText="权限" />
                <asp:BoundField ReadOnly="true" DataField="CreatDate" HeaderText="创建时间" />
                <asp:BoundField ReadOnly="true" DataField="lastIP" HeaderText="最近一次登陆IP" />
                <asp:CheckBoxField DataField="allow" HeaderText="使用状态" />
                <asp:CommandField ShowEditButton="True" />
                <asp:CommandField ShowSelectButton="True" />
                <asp:CommandField ShowDeleteButton="True"  />
             </Columns>
        </asp:GridView> 
cs中
SqlConnection myconn = new SqlConnection(@"Data Source=.\SQLEXPRESS;AttachDbFilename=|DataDirectory|\Math.mdf;Integrated Security=True;User Instance=True");
        myconn.Open();
        SqlCommand mycomd = new SqlCommand("StoredUserTable", myconn);
        SqlParameter[] prams =
            {   
                new SqlParameter("@UserID",SqlDbType.Int,4),
                new SqlParameter("@UserName",SqlDbType.Text,2147483647),
                new SqlParameter("@power",SqlDbType.NChar,10),
                new SqlParameter("@allow",SqlDbType.Bit,1),
                new SqlParameter("@CreatDate",SqlDbType.NChar,10),
                new SqlParameter("@lastDate",SqlDbType.NChar,10),
                new SqlParameter("@lastIP",SqlDbType.NChar,10)
            };
        //给参数赋值(FormView.Row.FindControl("Title") as TextBox).Text 
        prams[0].Value = ((TextBox)this.GridView1.Rows[e.RowIndex].Cells[0].Controls[0]).Text.ToString();
        prams[1].Value = ((TextBox)this.GridView1.Rows[e.RowIndex].Cells[0].Controls[1]).Text.ToString();
        prams[2].Value = ((TextBox)this.GridView1.Rows[e.RowIndex].Cells[0].Controls[2]).Text.ToString();
        prams[3].Value = ((TextBox)this.GridView1.Rows[e.RowIndex].Cells[0].Controls[3]).Text.ToString();
        prams[4].Value = ((TextBox)this.GridView1.Rows[e.RowIndex].Cells[0].Controls[4]).Text.ToString();
提示::指定的参数已超出有效值的范围。
参数名: index 
RowIndex怎么超了呢 prams[1].Value = ((TextBox)this.GridView1.Rows[e.RowIndex].Cells[0].Controls[1]).Text.ToString();
这一句
 

解决方案 »

  1.   

    prams[0].Value = ((TextBox)this.GridView1.Rows[e.RowIndex].Cells[0].Controls[0]).Text.ToString(); 
    prams[1].Value = ((TextBox)this.GridView1.Rows[e.RowIndex].Cells[1].Controls[0]).Text.ToString(); 
    prams[2].Value = ((TextBox)this.GridView1.Rows[e.RowIndex].Cells[2].Controls[0]).Text.ToString(); 
    prams[3].Value = ((TextBox)this.GridView1.Rows[e.RowIndex].Cells[3].Controls[0]).Text.ToString(); 
    prams[4].Value = ((TextBox)this.GridView1.Rows[e.RowIndex].Cells[4].Controls[0]).Text.ToString(); 
    提点建议,最好少用GridView; Text后面不必再跟ToString()
      

  2.   

    e.RowIndex].Cells[0].Controls[0]应该都设为0,如果你未设置过的话。贴子重复了。