2011-06-02 32 views
-3

可能重複:
System.NullReferenceException: Object reference not set to an instance of an object
System.NullReferenceException: Object reference not set to an instance of an objectSystem.NullReferenceException:對象不設置到對象的實例

我的代碼

if (ViewState["Edit"].ToString() == "new") 
{ 
}else{ 

    row = _section.GetBannerEntry(ViewState["Edit"].ToString()); 
} 

外觀在這個l上得到了錯誤INE

if (ViewState["Edit"].ToString() == "new") 

我換成

If (ViewState["Edit"] != null && ViewState["Edit"].ToString() == "new") 

它的工作原理,但現在我在這裏得到同樣的錯誤在其他

row = _section.GetBannerEntry(ViewState["Edit"].ToString()); 

請幫助

+4

你今天已經問過這三次了。請更新您的previos問題。 – Magnus 2011-06-02 10:54:09

+0

好的,我也在那裏 – shafiq 2011-06-02 10:58:46

+0

你可能想要刪除重複項。 – 2011-06-02 12:04:44

回答

0

沙菲克,「System.NullReferenceException :對象引用未設置爲對象的實例「當您嘗試使用它不是的對象時發生實例化。

  • _section
  • 的ViewState [ 「編輯」]

檢查兩個:

在行你所得到的錯誤可能所致。

+0

是的,我知道這是在ViewState [「編輯」] ...實際上這是空....我應該在第一次申報新的? – shafiq 2011-06-02 11:08:18

+0

你不知道。您可以設置該值,它不再爲空。如果你有時間,我認爲你應該閱讀一下關於viewstate的內容:http://msdn.microsoft.com/en-us/library/ms972976.aspx – Sergio 2011-06-02 11:39:44

相關問題