
无法将类型为“System.Web.UI.LiteralControl”的对象强制转换为类型“System.Web.UI
源码:SqlConnectionsqlcon=newSqlConnection(strCon);//定义查询字符串stringname=((TextBox)(GridVi...
源码: SqlConnection sqlcon = new SqlConnection(strCon);
//定义查询字符串
string name = ((TextBox)(GridView1.Rows[e.RowIndex].Cells[1].Controls[0])).Text.ToString().Trim();
string borntime = ((TextBox)(GridView1.Rows[e.RowIndex].Cells[2].Controls[0])).Text.ToString().Trim();
string money = ((TextBox)(GridView1.Rows[e.RowIndex].Cells[3].Controls[0])).Text.ToString().Trim();
string address = ((TextBox)(GridView1.Rows[e.RowIndex].Cells[4].Controls[0])).Text.ToString().Trim();
string code = ((TextBox)(GridView1.Rows[e.RowIndex].Cells[5].Controls[0])).Text.ToString().Trim();
string check = ((TextBox)(GridView1.Rows[e.RowIndex].Cells[6].Controls[0])).Text.ToString().Trim();
string updatestr = "update test set name='" + name + "', borntime='" + borntime + "' , money='" + money + "', address='" + address + "', code='" + code + "', check='" + check + "' where id=" + int.Parse(GridView1.DataKeys[e.RowIndex].Value.ToString().Trim());
后来改成如下就产生:未将对象引用设置到对象的实例提示错误
改后代码:
string name = ((TextBox)(GridView1.Rows[e.RowIndex].Cells[1].Controls[0]).FindControl("TextBox1")).Text.ToString().Trim();
string borntime = ((TextBox)(GridView1.Rows[e.RowIndex].Cells[2].Controls[0]).FindControl("TextBox1")).Text.ToString().Trim();
string money = ((TextBox)(GridView1.Rows[e.RowIndex].Cells[3].Controls[0]).FindControl("TextBox1")).Text.ToString().Trim();
string address = ((TextBox)(GridView1.Rows[e.RowIndex].Cells[4].Controls[0]).FindControl("TextBox1")).Text.ToString().Trim();
string code = ((TextBox)(GridView1.Rows[e.RowIndex].Cells[5].Controls[0]).FindControl("TextBox1")).Text.ToString().Trim();
string check = ((TextBox)(GridView1.Rows[e.RowIndex].Cells[6].Controls[0]).FindControl("TextBox1")).Text.ToString().Trim();
SqlCommand sqlcom = new SqlCommand(updatestr, sqlcon); //实例化SQL command对象
sqlcon.Open();
sqlcom.ExecuteNonQuery();
sqlcon.Close();
求高手帮忙解决一下。。。。。 展开
//定义查询字符串
string name = ((TextBox)(GridView1.Rows[e.RowIndex].Cells[1].Controls[0])).Text.ToString().Trim();
string borntime = ((TextBox)(GridView1.Rows[e.RowIndex].Cells[2].Controls[0])).Text.ToString().Trim();
string money = ((TextBox)(GridView1.Rows[e.RowIndex].Cells[3].Controls[0])).Text.ToString().Trim();
string address = ((TextBox)(GridView1.Rows[e.RowIndex].Cells[4].Controls[0])).Text.ToString().Trim();
string code = ((TextBox)(GridView1.Rows[e.RowIndex].Cells[5].Controls[0])).Text.ToString().Trim();
string check = ((TextBox)(GridView1.Rows[e.RowIndex].Cells[6].Controls[0])).Text.ToString().Trim();
string updatestr = "update test set name='" + name + "', borntime='" + borntime + "' , money='" + money + "', address='" + address + "', code='" + code + "', check='" + check + "' where id=" + int.Parse(GridView1.DataKeys[e.RowIndex].Value.ToString().Trim());
后来改成如下就产生:未将对象引用设置到对象的实例提示错误
改后代码:
string name = ((TextBox)(GridView1.Rows[e.RowIndex].Cells[1].Controls[0]).FindControl("TextBox1")).Text.ToString().Trim();
string borntime = ((TextBox)(GridView1.Rows[e.RowIndex].Cells[2].Controls[0]).FindControl("TextBox1")).Text.ToString().Trim();
string money = ((TextBox)(GridView1.Rows[e.RowIndex].Cells[3].Controls[0]).FindControl("TextBox1")).Text.ToString().Trim();
string address = ((TextBox)(GridView1.Rows[e.RowIndex].Cells[4].Controls[0]).FindControl("TextBox1")).Text.ToString().Trim();
string code = ((TextBox)(GridView1.Rows[e.RowIndex].Cells[5].Controls[0]).FindControl("TextBox1")).Text.ToString().Trim();
string check = ((TextBox)(GridView1.Rows[e.RowIndex].Cells[6].Controls[0]).FindControl("TextBox1")).Text.ToString().Trim();
SqlCommand sqlcom = new SqlCommand(updatestr, sqlcon); //实例化SQL command对象
sqlcon.Open();
sqlcom.ExecuteNonQuery();
sqlcon.Close();
求高手帮忙解决一下。。。。。 展开
2个回答
2011-09-23
展开全部
同意楼上的说法,肯定在后台“编辑“的响应事件中,添加了类似FindControl的方法,但是在类型转换的时候,强制转换的类型和原有的类型不符!
具体的说,就是你讲System.Web.UI.LiteralControl转换成System.Web.UI.WebControls.DropDownList了!
具体的说,就是你讲System.Web.UI.LiteralControl转换成System.Web.UI.WebControls.DropDownList了!
追问
该怎么修改??????我数据库有几个字段,类型分别是:int的id;varchar的姓名;money的薪酬;varchar的地址;varchar类型的审核字段
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
你可以试着强制转换一下看看!
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询