使用ADO进行Gridiview编辑.网 [英] Gridiview editing using ADO. net
本文介绍了使用ADO进行Gridiview编辑.网的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
大家好!
我想使用ADO.net编辑网格视图数据.我用了这段代码
Hi all!!
i Want to edit grid view data using ADO.net. I used this code
protected void GridView1_RowUpdating(object sender, GridViewUpdateEventArgs e)
{
objconnection.Open();
string id= GridView1.DataKeys[e.RowIndex ].Value.ToString();
GridViewRow row = GridView1.Rows[e.RowIndex];
TextBox txtUsername1 = (TextBox)row.FindControl("txtUsername");
TextBox txtPassword1 = (TextBox)row.FindControl("txtPassword");
TextBox txtStatus1 = (TextBox)row.FindControl("txtStatus");
objcommand= new SqlCommand ("update Def set username='" + txtUsername1.Text + "' , password='" + txtPassword1.Text + "' , status='" + txtStatus1.Text + "' where username='"+id+"'",objconnection );
objcommand.ExecuteNonQuery();
GridView1.EditIndex = -1;
databind();
}
它没有改变数据.当我使用断点时,我发现txtUsername1与项目模板中使用的txtUsername具有相同的文本,因此我无法更改数据.
问题是我无法访问在edittemplate字段中使用的文本框文本.
it''s not changing the data. when i used breakpoint i found that txtUsername1 has the same text that of txtUsername which i used in the item template therefore i am unable to change data.
the problem is that i am not able to access the textbox text that i have used in edittemplate field.
推荐答案
下面的代码可能会帮助您,亲爱的.... />
below code may help u dear....
GridViewRow row = (GridViewRow)GridView1.Rows[e.RowIndex];
Button btn = (Button)row.FindControl("Edit");
Label Id = (Label)row.FindControl("lbl_EmployeeId");
TextBox employeename = (TextBox)row.FindControl("txt_Ename");
TextBox Workstation = (TextBox)row.FindControl("txt_Workstation");
sq = "update Employee set Ename='+employeename & Workstation ='+Workstation where EmployeeID='+id";
SqlCommand cm = new SqlCommand(sq, con);
cm.ExecuteNonQuery();
bind();
这篇关于使用ADO进行Gridiview编辑.网的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文