Dynamically fill a GridView Dropdown with the next x years

A

Advertis

Is there a way to populate a dropdown in a GridView with the next x years?

I am using a GridView to display data from a SQL table One of the fields is
a Year. I want to have the dropdown list not only the year in the db field,
but also the current year to the next x years.

Any ideas?
 
P

Patrice

Just add 1 until the needed year ? What is the exact problem with what you
tried ? (add the items, looping for years, adding the combo etc...)
 
A

Advertis

here is the senerio:

I have a GridView on a Web Form. The GridView DataSourceID is using a
SqlDataSource to populate the rows in the GridView. The fields returned by
the datasource are: id, month, year. So the rows look somthing like this:

1 1 2003
2 5 2006
3 2 2006

First I changed the year column control in the GridView to a template field
and use a Dropdown. Now I need to add items to the dropdown list for each
row in the GridView to read somthing like this:

row 1 dropdown:
value text
2003 2003 selected
2006 2006
2007 2007
2008 2008
2009 2009

row2 dropdown:
2006 2006 selected
2007 2007
2008 2008
2009 2009

so on and so on

I'm not sure where I actually accomplish this. in the DataBound event, in
the RowAdded event. And then How this is accomplished.

Thanks
 
P

Patrice

I would use the RowDataBound event. You can get the current year using
e.DataItem. You can then add missing needed years to the dropdown...
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top