简体   繁体   English

获取在GridView中正在更新的当前行的值

[英]Get values of current row that is being updated in GridView

I have a GridView GridView1 and I want to 我有一个GridView GridView1 ,我想

 protected void GridView1_RowUpdating(object sender, GridViewUpdateEventArgs e)
{
    // Get value from row of GridView and update in query below... 
    SqlDataSource1.UpdateCommand = "UPDATE tblDonors SET DName = 'Dummy' WHERE DName = 'Test'";
}

How to get values of current row so that I can update that row in the Database. 如何获取当前行的值,以便我可以在数据库中更新该行。

I have tried this but does not work 我已经尝试过了,但是没有用

GridView1.Rows[e.RowIndex].Cells[0].Controls[0].ToString();

You need to use GridView1.EditIndex instead of e.RowIndex. 您需要使用GridView1.EditIndex而不是e.RowIndex。

TextBox Tb = (TextBox) GridView1.Rows[GridView1.EditIndex].FindControl("TextBox1");
if(tb!=null){
 string s = tb.Text;
}

Or Try this: 或尝试以下方法:

  TextBox Tb = (TextBox) GridView1.Rows[GridView1.EditIndex].Cells[0].Controls[0];
    if(tb!=null){
     string s = tb.Text;
    }

Also take a look at e.NewValues 还看看e.NewValues

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM