我正在更新gridview,问题出现在gridview文本框未包含的单元格中

时间:2018-09-03 10:59:50

标签: asp.net

标记:

<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();

显示错误

  

指定的参数超出有效值范围。

0 个答案:

没有答案