Asp.net 我正在更新gridview,问题发生在gridview文本框之外的单元格中
标记: 它显示了错误 指定的参数超出了有效值的范围Asp.net 我正在更新gridview,问题发生在gridview文本框之外的单元格中,asp.net,Asp.net,标记: 它显示了错误 指定的参数超出了有效值的范围 我怀疑你的索引被1-行关闭。单元格从0开始,而不是1。边不:请不要这样处理SQL命令文本-你的应用程序将容易受到攻击。我建议你看一看-从控件中删除数据不是asp.net的工作方式。Ok。我得到了它。非常感谢。 <asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" AutoGenerateDeleteButton
我怀疑你的索引被1-
行关闭。单元格
从0
开始,而不是1
。边不:请不要这样处理SQL命令文本-你的应用程序将容易受到攻击。我建议你看一看-从控件中删除数据不是asp.net的工作方式。Ok。我得到了它。非常感谢。
<asp:GridView
ID="GridView1"
runat="server"
AutoGenerateColumns="False"
AutoGenerateDeleteButton="True"
AutoGenerateEditButton="True"
DataKeyNames="id"
OnPageIndexChanging="GridView1_PageIndexChanging"
OnRowCancelingEdit="GridView1_RowCancelingEdit"
OnRowDeleting="GridView1_RowDeleting"
OnRowEditing="GridView1_RowEditing"
OnRowUpdating="GridView1_RowUpdating" >
<Columns>
<asp:BoundField DataField="id" HeaderText="id" InsertVisible="False" ReadOnly="True" SortExpression="id" />
<asp:BoundField DataField="Name" HeaderText="Name" SortExpression="Name" />
<asp:BoundField DataField="Password" HeaderText="Password" SortExpression="Password" />
<asp:BoundField DataField="City" HeaderText="City" SortExpression="City" />
<asp:BoundField DataField="Gender" HeaderText="Gender" SortExpression="Gender" />
<asp:BoundField DataField="Mail" HeaderText="Mail" SortExpression="Mail" />
</Columns>
</asp:GridView>
int userid = Convert.ToInt32(GridView1.DataKeys[e.RowIndex].Value.ToString());
GridViewRow row = (GridViewRow)GridView1.Rows[e.RowIndex];
string Label1Text = ((TextBox)row.Cells[2].Controls[0]).Text;
string e_id = ((TextBox)row.Cells[1].Controls[0]).Text;
string e_Name = ((TextBox)row.Cells[2].Controls[0]).Text;
string e_Password = ((TextBox)row.Cells[3].Controls[0]).Text;
string e_City = ((TextBox)row.Cells[4].Controls[0]).Text;
string e_Gender = ((TextBox)row.Cells[5].Controls[0]).Text;
string e_Mail = ((TextBox)row.Cells[6].Controls[0]).Text;
GridView1.EditIndex = -1;
SQLConn.Open();
SqlCommand cmd = new SqlCommand("update tblregi set Name='" + e_Name + "', Password='" + e_Password + "',city='" + e_City + "', Gender='" + e_Gender + "', Mail='" + e_Mail + "'where id='" + e_id + "'", SQLConn);
cmd.ExecuteNonQuery();
SQLConn.Close();
gvbind();