0
votes

Hi I got an error when try to click the linkbutton at the column. This error only occur when I expand all the detail table at the same time. The error shown is Object reference not set to an instance of an object. Below is my codes. Please help. Thanks

   Protected Sub lnkID_Select(ByVal sender As Object, ByVal e As EventArgs)

            Dim MerchantID As String = ""
            Dim BranchNum As String = ""

            Dim dt As GridDataItem = DirectCast(sender, LinkButton).NamingContainer
            MerchantID = CType(RadGrid1.Items(dt.ItemIndex).FindControl("lnkMerchantID"), LinkButton).Text
            BranchNum = CType(RadGrid1.Items(dt.ItemIndex).FindControl("BranchNum"), Label).Text

            Response.Redirect("~/Master/Merchant/MerchantDetail.aspx?MerchantID=" & MerchantID & "&BranchNum=" & BranchNum & "")
    End Sub
1
Where is the line that throws the error? - Brian Mains
This line throw error MerchantID = CType(RadGrid1.Items(dt.ItemIndex).FindControl("lnkMerchantID"), LinkButton).Text - user3051461

1 Answers

0
votes

The only reasons you would get that error, for this line:

MerchantID = CType(RadGrid1.Items(dt.ItemIndex).FindControl("lnkMerchantID"), LinkButton).Text

RadGrid1.Items(dt.ItemIndex) - this returns null, but most likely, if out of range, a different error would be thrown. FindControl("lnkMerchantID") - This returns null, or a type other than LinkButton. If not a LinkButton, it would return null from the CType.

Those are the only possible reasons, with the most likely culprit being that it can't find lnkMerchantID.