简体   繁体   中英

Auto-generate template fields OR gridviews?

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.

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM