2014-06-20 41 views
-3
Protected Sub foo_Click(ByVal sender As Object, ByVal e As CommandEventArgs) 

      Dim a As LinkButton = CType(Repeater1.FindControl("Linkbutton1"), LinkButton) 
    a.Enabled = False 
End Sub 

當我嘗試獲得「對象引用未設置爲對象的實例」。當我點擊鏈接按鈕。當訪問linkbutton獲取「對象引用未設置爲對象的實例」時。

+0

'Repeater1.FindControl(「Linkbutton1」)'可能返回'Nothing'。 –

+0

linkbutton在項目模板中使用。這些值會顯示出來,但是當我點擊它時我會得到這個異常。 –

回答

0

似乎你正在尋找中繼器級別的Linkbutton1。您可能需要做的是在行/項目級搜索Linkbutton1。下面是從中繼器禁用所有Linkbutton1一個例子:

Protected Sub foo_Click(sender As Object, e As EventArgs) 
    For Each r As RepeaterItem In Repeater1.Items 
     Dim a As LinkButton = DirectCast(r.FindControl("Linkbutton1"), LinkButton) 
     a.Enabled = False 
    Next 
End Sub 

希望這有助於!

相關問題