簡體   English   中英

ASP.NET中的GridView NullReferenceException錯誤

[英]GridView NullReferenceException Error in ASP.NET

我正在GridView中訪問TextField。 它不應該選擇更新的文本,而是僅獲取原始文本。 我在同一頁面的不同選項卡中使用兩個GridView。 這會使它們相互影響嗎?

但是GridView給了我一個例外:

OnlineExamDesign.dll中發生了類型為'System.NullReferenceException'的異常,但未在用戶代碼中處理。 附加信息:對象引用未設置為對象的實例。

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();
            }

試試這個代碼:

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

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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM