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();
这一句
<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();
这一句
解决方案 »
- 关于一道笔试题很多人说有问题的,我是出题原作者,说说我的感悟
- ASP.NET WEB 服务应用程序中gridview如何才能显示图片
- windform里面把窗体的边框设置成没有的时候,怎么样让鼠标可以移动它?
- datagridview与datatable的绑定方法
- 我刚学treeview控件,不知怎么用呢,谢谢大家帮我一下
- 知道利用网卡的MAC算注册码的代码,能帮我写个注册机吗?
- 如何从A窗体登录到B窗体后关闭A窗体
- 提问:项目的文件目录如何规划?(做过一个工程中超过20个子项目的进)
- 用鼠标画一个矩形框,鼠标释放时点的坐标和矩形框的right和bottom点的坐标不一致?
- vs2005在2003系统的棘手问题请教
- 如何改变绑定到数据库的numericUpDown值
- 畅谈C#写手机软件心得!!小抛分下……
this.GridView1.Rows[e.RowIndex].Cells[0].Text