0

I have an ASP .NET Datagrid in which I am trying to hide the delete and edit button columns if a certain condition is true (say, the value in one of the columns is X). I found a solution that is exactly what I need here;

Conditionally hide CommandField or ButtonField in Gridview

But it is for a GridView. I have not been able to find anything similar for a Datagrid, and I am not able to implement that solution. Does anyone have a solution similar to the one linked above, but for data grids? Thanks!

Community
  • 1
  • 1
Archetype90
  • 179
  • 1
  • 4
  • 19

2 Answers2

0

You can use same solution for datagrid also:

<asp:Button ID="btnReject" runat="server" CommandName="Reject" Visible='<%# DataBinder.Eval(Container.DataItem, "Age") > 35 ? 1 : 0 %>' CommandArgument='<%# Eval("ID") %>'></asp:Button> 
Sandeep
  • 1,182
  • 3
  • 11
  • 26
0

Beside using the DataBinder.Eval, which is much simpler approach, you could also use the `GridHeaderText' to hide the columns.

See this link for more on how to hide DataGrid columns via HeaderText

ANewGuyInTown
  • 5,957
  • 5
  • 33
  • 45