rcowen00
asked on
Gridview Hide Delete on Certain Records but show empty column
I have the following and it works, but it removes the column when there is no Delete link. I would like the column to show, but be empty when there is no delete link.
Protected Sub txtAddendum_RowDataBound(sender As Object, e As System.Web.UI.WebControls.GridViewRowEventArgs) Handles txtAddendum.RowDataBound
If e.Row.RowType = DataControlRowType.DataRow Then
Dim drv As DataRowView = TryCast(e.Row.DataItem, DataRowView)
If drv("OrdersAddendum").ToString().Equals("0") Then
e.Row.Cells(0).Visible = False
Else
e.Row.Cells(0).Visible = True
End If
End If
End Sub
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
I use a TemplateField for setting visibility like:
<asp:TemplateField HeaderText="Delete" HeaderStyle-Width="30px" HeaderStyle>
<ItemTemplate>
<asp:LinkButton ID="DeleteButton" runat="server" CommandName= "Delete" Visible='<%#IsVisible(Eval("IsPending"))%>' />
</ItemTemplate>
</asp:TemplateField>
In Code-behind IsVisible method looks like this:Public Function IsVisible(ispending As Object) As Boolean
Return Not CBool(ispending)
'You can use any logic here to determine whether to return true or false
End Function
Open in new window
use:Open in new window
which should keep the table structure but hide the controls inside the cell.** this is c#. I don't know VB enough not to jack up some syntax. You should be able to figure out how it's working, though, and fix it accordingly ("Dim c As Control" instead of "Control c", etc.)