【发布时间】:2014-06-30 06:18:27
【问题描述】:
我是 asp.net 的新手,我一直在尝试上述问题一段时间,但没有任何成功。这是我在 roweditevent 中的代码
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 没有被找到。您在哪一行得到异常?
-
但我在行更新事件中使用了相同的代码,它工作正常
-
所以没有找到
Name。你确定 txtboxname 实际上是正确的吗? -
是的,我也应该给行更新代码
-
拜托,如果有人能找到问题所在,请发布...