无法将类型为“System.Web.UI.LiteralControl”的对象强制转换为类型“System.Web.UI.WebControls.TextBox 10
protectedvoidGridView1_RowUpdating(objectsender,GridViewUpdateEventArgse){SqlConnecti...
protected void GridView1_RowUpdating(object sender, GridViewUpdateEventArgs e)
{
SqlConnection conn = Connection.Connect();
string sqlstr = "update cpxx set cpname='"
+ ((TextBox)(GridView1.Rows[e.RowIndex].Cells[1].Controls[0])).Text .ToString().Trim() + "',liuti='"
+ ((TextBox)(GridView1.Rows[e.RowIndex].Cells[2].Controls[0])).Text .ToString().Trim() + "',weidu='"
+ ((TextBox)(GridView1.Rows[e.RowIndex].Cells[3].Controls[0])).Text .ToString().Trim() + "',tedian='"
+ ((TextBox)(GridView1.Rows[e.RowIndex].Cells[4].Controls[0])).Text .ToString().Trim() + "',zhuansu='"
+ ((TextBox)(GridView1.Rows[e.RowIndex].Cells[5].Controls[0])).Text .ToString().Trim() + "' where id='"
+ GridView1.DataKeys[e.RowIndex].Value.ToString() + "'";
SqlCommand cmd = new SqlCommand(sqlstr, conn);
conn.Open();
cmd.ExecuteNonQuery();
conn.Close();
GridView1.EditIndex = -1;
bind(); 展开
{
SqlConnection conn = Connection.Connect();
string sqlstr = "update cpxx set cpname='"
+ ((TextBox)(GridView1.Rows[e.RowIndex].Cells[1].Controls[0])).Text .ToString().Trim() + "',liuti='"
+ ((TextBox)(GridView1.Rows[e.RowIndex].Cells[2].Controls[0])).Text .ToString().Trim() + "',weidu='"
+ ((TextBox)(GridView1.Rows[e.RowIndex].Cells[3].Controls[0])).Text .ToString().Trim() + "',tedian='"
+ ((TextBox)(GridView1.Rows[e.RowIndex].Cells[4].Controls[0])).Text .ToString().Trim() + "',zhuansu='"
+ ((TextBox)(GridView1.Rows[e.RowIndex].Cells[5].Controls[0])).Text .ToString().Trim() + "' where id='"
+ GridView1.DataKeys[e.RowIndex].Value.ToString() + "'";
SqlCommand cmd = new SqlCommand(sqlstr, conn);
conn.Open();
cmd.ExecuteNonQuery();
conn.Close();
GridView1.EditIndex = -1;
bind(); 展开
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询