我用SqlDataSource读取了数据库中的一张表(T1)并绑定了一个GridView。
在GridView在创建了一个模板列,里面放了一个TextBox控件,并双向绑定了T1中的一个字段(A1)。我想通过一个Button事件,把我写在GridView的TextBox中的数据批量更新到T1表中。因该怎么做?谢谢
在GridView在创建了一个模板列,里面放了一个TextBox控件,并双向绑定了T1中的一个字段(A1)。我想通过一个Button事件,把我写在GridView的TextBox中的数据批量更新到T1表中。因该怎么做?谢谢
GridViewRow gridRow;
TextBox priceTextBox;
int Price, Id;
// 遍历GridView中的每一行
for (int i = 0; i < rowsCount; i++)
{
// 获行当前行
gridRow = GridView1.Rows[i];
// 通过DATAKEYS来取行没显示出来的ID号
Id = Convert.ToInt32(GridView1.DataKeys[i].Value);
//
priceTextBox = (TextBox)gridRow.FindControl("TextBox2");
// 转换为整形,如果输入的是非法字符Int32.TryParse返回FALSE
if (Int32.TryParse(priceTextBox.Text, out Price))
{
// 调用业务层的方法更新数据
ServerTableBll ServerTableUpdate = new ServerTableBll();
ServerTableUpdate.UpdateServerTable(Id, Price.ToString());
}
else
{
// 更新失败
}
// 显示信息
//statusLabel.Text = success ?
//"<br />更新成功!<br />" :
//"<br />更新失败!<br />";
}
配合UpdateCommand="Update [Student] Set Title = @Title Where id=@id"
会报@Title没有申明,我把@去掉后,并把UpdateCommand改成="Update [Student] Set Title = Title Where id=id"执行是通过了,但表里的数据根本没有改变,我跟踪了一下,Title和ID里都是有值得,怎么会这样?