Hi, I have a child gridview with a linkbutton where I'm trying to hide the linkbutton if e.Row.Cells(0) is empty. I'm able to find the linkbutton on a standalone gridview, but nested appears to be different. (edit: current error is "lnkbtn object reference not set to an instance of an object). Thanks in advance.
Protected Sub gvDepartment_RowDataBound(sender As Object, e As GridViewRowEventArgs) Handles gvDepartment.RowDataBound
If e.Row.RowType = DataControlRowType.DataRow Then
Dim id As String = gvDepartment.DataKeys(e.Row.RowIndex).Value.ToString()
Dim gvChild As GridView = TryCast(e.Row.FindControl("gvEmployees"), GridView)
gvChild.DataSource = GetData2(String.Format("SELECT * FROM tblFiles WHERE ID='{0}'", id)) gvChild.DataBind() gvChild.Columns(4).ItemStyle.Wrap = False
Dim lbRT As LinkButton = TryCast(Me.Master.FindControl("Maincontent").FindControl("lnkDownload"), LinkButton)
'e.Row.BackColor = Color.Gray
If gvChild IsNot Nothing Then
Dim lnkbtn As LinkButton = TryCast(e.Row.FindControl("lnkDownload"), LinkButton)
For Each row As GridViewRow In gvChild.Rows
If e.Row.RowType = DataControlRowType.DataRow Then
If e.Row.Cells(0).Text.Equals(" ") Then
lnkbtn.Visible = False
End If
End If
Next
End If
End If
End Sub
Amira BedhiafiPosted Jan 15, 2025, 10:16 PM
You're trying to find the
LinkButtonwithin the parentGridView(gvDepartment) instead of the childGridView(gvEmployees). Another thing thelnkbtnobject reference error occurs becauselnkbtnis being searched for in the parent row, where it doesn't exist as expected.