方法一:
var txtName = grid1.Rows[e.RowIndex].Cells[0].FindControl("txtName") as TextBox;
if (txtName != null)
{
// 读取值
//
}
方法二:
// 更新
protected void grid1_RowUpdating(object sender, GridViewUpdateEventArgs e)
{
var row = grid1.Rows[e.RowIndex];
// 提取 Id 字段的值
grid1.Columns[0].ExtractValuesFromCell(
e.Keys,
row.Cells[0] as DataControlFieldCell,
DataControlRowState.Edit,
true /* include readonly */);
// 提取 Name 字段的值
grid1.Columns[1].ExtractValuesFromCell(
e.NewValues,
row.Cells[1] as DataControlFieldCell,
DataControlRowState.Edit,
true /* include readonly */);
var id = int.Parse(e.Keys["id"].ToString());
var name = (string) e.NewValues["name"];
// 执行相关的数据库更新操作
//
本文介绍了两种使用ASP.NET中GridView控件进行数据更新的方法。第一种方法通过直接获取指定行列的TextBox控件来读取值;第二种方法展示了如何在RowUpdating事件中提取Id和Name字段的值,并执行相应的数据库更新操作。
713

被折叠的 条评论
为什么被折叠?



