- 爱易网页
-
ASP.NET教程
- 一个关于sqldatasource更新的小疑点
日期:2014-05-18 浏览次数:20460 次
一个关于sqldatasource更新的小问题
protected void GridView1_RowUpdating(object sender, GridViewUpdateEventArgs e)
{
try
{
TextBox fcardpwd = (TextBox)GridView1.Rows[e.RowIndex].Cells[3].Controls[1];
TextBox fask = (TextBox)GridView1.Rows[e.RowIndex].Cells[4].Controls[1];
TextBox fanswer = (TextBox)GridView1.Rows[e.RowIndex].Cells[5].Controls[1];
TextBox fzt = (TextBox)GridView1.Rows[e.RowIndex].Cells[6].Controls[1];
TextBox fstartime = (TextBox)GridView1.Rows[e.RowIndex].Cells[7].Controls[1];
TextBox fendtime = (TextBox)GridView1.Rows[e.RowIndex].Cells[8].Controls[1];
string fcardid = this.GridView1.DataKeys[e.RowIndex].ToString();
SqlDataSource1.UpdateCommand = "update fuser set fcardpwd=@fcardpwd,fask=@fask,fanswer=@fanswer,fzt=@fzt,fstartime=@fstartime,fendtime=@fendtime where fcardid=@fcardid ";
SqlDataSource1.UpdateParameters.Add( "fcardpwd ", fcardpwd.Text.Trim());
SqlDataSource1.UpdateParameters.Add( "fask ", fask.Text.Trim());
SqlDataSource1.UpdateParameters.Add( "fanswer ", fanswer.Text.Trim());
SqlDataSource1.UpdateParameters.Add( "fzt ", fzt.Text.Trim());
SqlDataSource1.UpdateParameters.Add( "fstartime ", fstartime.Text.Trim());
SqlDataSource1.UpdateParameters.Add( "fendtime ", fendtime.Text.Trim());
SqlDataSource1.UpdateParameters.Add( "fcardid ", fcardid);
SqlDataSource1.Update();
}
catch {
this.Response.Write( " <script> window.alert( '出现错误,请与管理员联系 ') </script> ");
}
}