I'm trying to conditionally hide a template column within the Gridview, I've tried the following, but this doesn't work. Is there a way to do this within the .aspx?
<asp:TemplateField HeaderText="Grade" SortExpression="grade" Visible='<%# Convert.ToDouble(Eval("grade")) == 0 ? true : false %>'>
<ItemTemplate>
<%# string.Format("{0:0.#}", Convert.ToDouble(Eval("grade"))) %>
</ItemTemplate>
</asp:TemplateField>
you can do all of your conditional formatting (colors, hide etc.) by using the itemDataBound event. However, your sample markup does not seem to have a control - and you want to have a control for that information. And that control should have some kind of "id" or name that you can refernce in code.
However, since you did not provide much of the markup? Then I give a example for both the cells collection, and the controls that you might have.
So, say we have this simple grid view. Note how the last two fields are both City, one is a bound field (often common), and the other is a label (but could be a text box or just about any asp.net control).
Ok, on page load, we load up the above grid with this code:
Ok, we get this output:
Now, lets hide a column, based on say city. We say City = "Edmonton", we hide the control.
So, you use the itemData bound event.
I have in this sample both the bound fields (cells) collection hide example, and also for how do you do this with templated controls (find control).
So, the code is this:
And now the output is this: