Reputation: 2454
I am trying to add some filters to a gridview that I am working on, and I'm wondering if it is possible to generate links or buttons above the gridview based on the years returned in the dataset. For example, if my dataset contains dates from 2001, 2009, and 2031 in my date column, I would like to be able to take that data from my SQL query (getting a distinct list of years is not an issue), and generate the buttons. From there, I would filter the data in the gridview based on the user clicking the buttons.
Is dynamic generation of buttons possible in ASP.NET? I do have some other ideas of how to accomplish the same functionality, but I would prefer to do it this way.
Thanks,
badPanda
Upvotes: 0
Views: 266
Reputation: 7266
You can use another databound control e.g. a repeater that has a Button or LinkButton in it's ItemTemplate. Bind this control to your Years list. Set the Text Property of the button to display the year.
Upvotes: 1