求助,GridView 的数据源是动态绑定的,需要编辑然后更新怎么实现
string sql = "select * from xianjinliuliangbiao "; public void Data(string sql)
{
OleDbConnection conn = new OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + Server.MapPath("~/DB_Data/caiwu.mdb"));
DataSet ds = new DataSet();
OleDbDataAdapter dadt = new OleDbDataAdapter(sql, conn);
dadt.Fill(ds);
this.GridView1.DataSource = ds;
GridView1.DataBind();
}
public void Data1(string sql)
{
OleDbConnection conn = new OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + Server.MapPath("~/DB_Data/caiwu.mdb"));
DataSet ds = new DataSet();
OleDbDataAdapter dadt = new OleDbDataAdapter(sql, conn);
dadt.Fill(ds);
}
protected void GridView1_RowCancelingEdit(object sender, GridViewCancelEditEventArgs e)
{
this.GridView1.EditIndex = -1;
Data(sql);
}
protected void GridView1_RowUpdating(object sender, GridViewUpdateEventArgs e)
{
string id = GridView1.DataKeys[e.RowIndex].Values[0].ToString();
string nf = ((TextBox)(GridView1.Rows[e.RowIndex].Cells[1].Controls[0])).Text.ToString().Trim();
string jyhd = ((TextBox)(GridView1.Rows[e.RowIndex].Cells[2].Controls[0])).Text.ToString().Trim();
string tzhd = ((TextBox)(GridView1.Rows[e.RowIndex].Cells[3].Controls[0])).Text.ToString().Trim();
string czhd = ((TextBox)(GridView1.Rows[e.RowIndex].Cells[4].Controls[0])).Text.ToString().Trim();
string hlbd = ((TextBox)(GridView1.Rows[e.RowIndex].Cells[5].Controls[0])).Text.ToString().Trim();
string xjzje = ((TextBox)(GridView1.Rows[e.RowIndex].Cells[6].Controls[0])).Text.ToString().Trim();
string qmye = ((TextBox)(GridView1.Rows[e.RowIndex].Cells[7].Controls[0])).Text.ToString().Trim();
string Sql = "update xianjinliuliangbiao set 年份='" + nf + "',经营活动产生的资金流量='" + jyhd+ "',投资活动产生的资金流量='" + tzhd + "',筹资活动产生的资金流量='" + czhd + "',汇率变动对现金及现金等价物的影响='" +hlbd + "',现金及现金等价物净增加额='" + xjzje + "',期末现金及现金等价物余额='" + qmye + "'";
Data1(Sql);
Data(sql);
}
错误提示是:无法将类型为“System.Web.UI.LiteralControl”的对象强制转换为类型“System.Web.UI.WebControls.TextBox”。