0

This question is related to Changing hardcoded dates to dynamic.

Long story short, I have a gridview with a bunch of templatefields for dates that are hardcoded in. I need these templatefields to change based on a boolean in the code behind. Is it possible to auto-generate these based on what the bool is equal to?

Would making two sets of gridviews be a viable option and have only have one visible at a time based on the bool?

I did some code-behind stuff to make the correct dates in the templatefields, but whenever there is a callback (which I can't modify or get rid of), the gridview and templatefields revert back to the ones hardcoded in the .aspx file.

Community
  • 1
  • 1
pfinferno
  • 1,779
  • 3
  • 34
  • 62

1 Answers1

1

Why don't just

<TemplateField>
  <% if ( boolFromCodebehind ) { %>
  Hardcoded date 1
  <% } else { %>
  or even <%= codebehindVariable %>
  <% } %>
<TemplateField>

Such conditional markup works outside of templates but I hope it works there too.

Wiktor Zychla
  • 47,367
  • 6
  • 74
  • 106
  • Didn't know you could do that (I'm new to .asp). However, trying something like you suggested gave me an error "The server tag is not formed well". I updated my post with relevant code. – pfinferno Jan 04 '16 at 19:02
  • Nevermind, had a > in the wrong place. Your answer is what I was looking for. Thank you! – pfinferno Jan 04 '16 at 20:26