在RowUpdating的事件里,怎么样获取
<asp:BoundField> </asp:BoundField>
里的值???
protected void GridView1_RowUpdating(object sender, GridViewUpdateEventArgs e)
{
try
{
GridViewRow myrow = GridView1.Rows[e.RowIndex];
string name = ((TextBox)myrow.Cells[1].Controls[0]).Text;
string pwd = ((TextBox)myrow.Cells[2].Controls[0]).Text;
string sql = "update dc4_user_def set username= ' " + name + " ',password= ' " + pwd + " 'where userid= ' " + userid + " ' ";
DBHelper.ExcuteQuery(sql);
GridView1.EditIndex = -1;
this.BindGridView();
}
catch (Exception ex)
{
Response.Write(ex.Message);
}
}
<asp:BoundField> </asp:BoundField>
里的值???
方法1:
try something like
GridViewRow row = GridView1.Rows[e.RowIndex];
if (row != null)
{
TextBox tb = row.Cells[n].Controls[0] as TextBox; //change n to the position of your bound field
if (tb != null)
{
Response.Write(tb.Text);
}
}
GridViewRow row = GridView1.Rows[e.RowIndex];
if (row != null)
{
TextBox tb = row.Cells[n].Controls[0] as TextBox; //change n to the position of your bound field
if (tb != null)
{
Response.Write(tb.Text);
}
}
或
protected void GridView1_RowUpdating(object sender, GridViewUpdateEventArgs e)
{
try
{
GridViewRow myrow = GridView1.Rows[e.RowIndex];
string name = ((TextBox)myrow.Cells[1].Controls[0]).Text;
string pwd = ((TextBox)myrow.Cells[2].Controls[0]).Text;
string sql = "update dc4_user_def set username= ' " + name + " ',password= ' " + pwd + " 'where userid= ' " + userid + " ' ";
DBHelper.ExcuteQuery(sql);
GridView1.EditIndex = -1;
this.BindGridView();
}
catch (Exception ex)
{
Response.Write(ex.Message);
}
}