GridView1_RowUpdating更新不了,求助
代码如下:
protected void GridView1_RowUpdating1(object sender, GridViewUpdateEventArgs e)
{
string strConn = System.Configuration.ConfigurationManager.AppSettings["DSN"];
SqlConnection conn = new SqlConnection(strConn);
conn.Open();
string s1 = GridView1.DataKeys[e.RowIndex].Value.ToString();
string s2 = ((TextBox)(GridView1.Rows[e.RowIndex].Cells[1].Controls[0])).Text;
string s3 = ((TextBox)(GridView1.Rows[e.RowIndex].Cells[2].Controls[0])).Text;
string s4 = ((TextBox)(GridView1.Rows[e.RowIndex].Cells[3].Controls[0])).Text;
string s5 = ((TextBox)(GridView1.Rows[e.RowIndex].Cells[4].Controls[0])).Text;
string sql = "update 户型资料表 set 户型='" + s2 + "',房型='" + s3 + "',套内面积='" + s4 + "',简介='" + s5 + "' where 户型编号='" + s1 + "'";
SqlCommand cmd = new SqlCommand(sql, conn);
cmd.ExecuteNonQuery();
conn.Close();
}
数据库表如下:
<asp:GridView ID="GridView1" runat="server" Height="217px" Width="651px" AllowPaging="True" BackColor="White" BorderColor="#DEDFDE" BorderStyle="None" BorderWidth="1px" CellPadding="4" EnableSortingAndPagingCallbacks="True" PageSize="5" AllowSorting="True" AutoGenerateColumns="False" ForeColor="Black" GridLines="Vertical" OnRowCancelingEdit="GridView1_RowCancelingEdit" OnRowDeleting="GridView1_RowDeleting" OnRowEditing="GridView1_RowEditing" OnRowUpdating="GridView1_RowUpdating1" DataKeyNames="户型编号" >
<FooterStyle BackColor="#CCCC99" />
<RowStyle BackColor="#F7F7DE" />
<SelectedRowStyle BackColor="#CE5D5A" Font-Bold="True" ForeColor="White" />
<PagerStyle ForeColor="Black" HorizontalAlign="Right" BackColor="#F7F7DE" />
<HeaderStyle BackColor="#6B696B" Font-Bold="True" ForeColor="White" />
<Columns>
<asp:BoundField DataField="户型编号" HeaderText="户型编号" SortExpression="户型编号" />
<asp:BoundField DataField="户型" HeaderText="户型" SortExpression="户型" />
<asp:BoundField DataField="房型" HeaderText="房型" SortExpression="房型" />
<asp:BoundField DataF