【问题标题】:GridView NullReferenceException Error in ASP.NETASP.NET 中的 GridView NullReferenceException 错误
【发布时间】:2017-01-20 07:02:18
【问题描述】:

我正在访问 GridView 中的 TextField。它不应该选择更新的文本,而是只采用原始文本。我在不同选项卡的同一页面中使用两个 GridView。这会让它们相互影响吗?

但是 GridView 给了我一个例外:

“System.NullReferenceException”类型的异常发生在 OnlineExamDesign.dll 中,但未在用户代码中处理。 附加信息:对象引用未设置为对象的实例。

else if (e.CommandName == "UpdateRowTeam")
            {
                DomainTeam updateObj = new DomainTeam();
                int rowIndex = ((GridViewRow)((LinkButton)e.CommandSource).NamingContainer).RowIndex;
                int index = Convert.ToInt32(e.CommandArgument);
                string name = ((TextBox)domainGrid.Rows[rowIndex].FindControl("txtchangeTeamName")).Text;
                updateObj.actionTeam(index,name,"TeamUpdate");
                teamGrid.EditIndex = -1;
                getTeamGridData();
            }

【问题讨论】:

标签: c# asp.net .net gridview


【解决方案1】:

试试这个代码:

GridViewRow row = (GridViewRow)((Button)sender).NamingContainer;
 TextBox TextBox1 = row.FindControl("TextBox1") as TextBox; 

  string myString = TextBox1.Text; //Access TextBox1 here.

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-07-28
    • 1970-01-01
    • 2013-11-10
    • 2016-03-02
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多