Iam新的asp.net和我一直在尝试上述问题一段时间没有任何成功。这里是我的代码在roweditevent如何在点击编辑按钮时在gridview中获得文本框的值?
GridView1.EditIndex = e.NewEditIndex;
int newindex = e.NewEditIndex;
TextBox NAME = GridView1.Rows[newindex].FindControl("txtboxname") as TextBox;
string gridupdat = NAME.Text;
但在调试我总是得到空引用那里。
这是我行的更新代码,它工作正常
Label ID = GridView1.Rows[e.RowIndex].FindControl("ID") as Label;
TextBox NAME = GridView1.Rows[e.RowIndex].FindControl("txtboxname") as TextBox;
DropDownList STATUS = GridView1.Rows[e.RowIndex].FindControl("dropdownstatus") as DropDownList;
string string1 = NAME.Text;
if (fetchmail(string1, labelgrid999) == true)
{
string updatquery = string.Format("UPDATE Compliance_Tracker.dbo.verificationMaster SET NAME='{0}',STATUS='{1}' WHERE ID = {2}", NAME.Text, STATUS.Text, Convert.ToInt32(ID.Text));
string dupquery = "select COUNT(*) from Compliance_Tracker.dbo.verificationMaster where Compliance_Tracker.dbo.verificationMaster.NAME = '" + NAME.Text + "';";
if (obj4.isDuplicate(dupquery) == false)
{
GridView1.EditIndex = -1;
string populatequery = updatquery + ";select NAME,(case when STATUS='1' then 'Active' when STATUS='0'then 'Inactive' ELSE 'UNKNOWN' END)as STATUS,ID from Compliance_Tracker.dbo.verificationMaster;";
obj4.BindGridData(populatequery, GridView1);
}
else
{
ClientScript.RegisterStartupScript(this.GetType(), "myalert", "alert('" + "Username already exists" + "');", true);
}
}
else
{
string myStringVariable = "Please enter valid username";
ClientScript.RegisterStartupScript(this.GetType(), "myalert", "alert('" + myStringVariable + "');", true);
}
我猜你txtboxname没有被发现。你在哪条线上得到例外? – Matthijs
在第四行 – krishb591993
但我已经在行更新事件中使用了相同的代码,它工作正常 – krishb591993