473,623 Members | 3,366 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Dynamically fill a GridView Dropdown with the next x years

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?
Jun 6 '06 #1
3 2099
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...)

--

"Advertis" <ad******@snpen t.com> a écrit dans le message de news:
kq************* **@tornado.tamp abay.rr.com...
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?

Jun 6 '06 #2
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
"Patrice" <sc****@chez.co m> wrote in message
news:ur******** ******@TK2MSFTN GP04.phx.gbl...
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...)

--

"Advertis" <ad******@snpen t.com> a écrit dans le message de news:
kq************* **@tornado.tamp abay.rr.com...
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?


Jun 6 '06 #3
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...

--
Patrice

"Advertis" <ad******@snpen t.com> a écrit dans le message de news:
GM************* **@tornado.tamp abay.rr.com...
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
"Patrice" <sc****@chez.co m> wrote in message
news:ur******** ******@TK2MSFTN GP04.phx.gbl...
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...)

--

"Advertis" <ad******@snpen t.com> a écrit dans le message de news:
kq************* **@tornado.tamp abay.rr.com...
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?



Jun 6 '06 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

8
3381
by: utterberg | last post by:
Hi I'm adding two dropdownlist in my webform by clicking a button. I fill the first dropdown with some values from my DB and the other one when I choose from the first dropdown. But since theese dropdownlists are created by clicking a button they no longer exists on my webform. How do I keep my dynamically created dropdown when using OnSelectedIndexChanged? Can anyone help me solve this problem? Or is there a better way of doing this?
0
1880
by: yeltsin27 | last post by:
I need some advice on handling dynamically added controls in a GridView. My app takes an uploaded CSV file containing addresses, converts it to a DataTable, databinds the DataTable to a GridView, accepts information via dropdowns embedded in the first row of the GridView about which incoming fields should go to which database fields, and writes the data to the database. The incoming data has an arbitrary number of columns so I create...
0
1037
by: B | last post by:
I was wondering if somebody could point me in the right direction, I have a gridview and it contains a dropdown list, and what I want to do is, than when the dropdown list is modified I want to insert today's date in the next cell. I have everyting working..meaning the gridview, the dropdown list..the update except I can't for the life of me figure out how to conditionaly modify the values in cells.
1
7759
by: mitchman10 | last post by:
My Time table has TimeID,Employee,PayPeriod,ChargeCodeID,Hours My Chargecode table has ChargecodeID,c_Text I need an Editable datagrid that will show the TimeID,Employee,PayPeriod,C_Text in a label and hours, along with an edit linkbutton. When they click on edit, the edit button turns to Update Cancel TimeID stays read Only
9
7920
by: Chris | last post by:
I am dynamically adding a user control to each row in a gridview. The reason I am doing it dynamically is the user control is different depending on certain data in the gridview. The gridview contains a placeholder and I add the control to it, the user control is a formview bound to an object datsource. This works great until I post back the page and the user control disappears. What am I doing wrong? Regards, Chris. Protected Sub...
0
1564
by: lianaent | last post by:
Hi All, I'm brand new to asp.net 2.0, and have a simple task of just creating a quick and dirty data entry form with SQL Server 2005 on the back end. I added a gridview to my form, and I can populate it dynamically by choosing from a dropdown that I populate dynamically from the database sys.tables table. When I choose a table from my dropdown, poof, the gridview is beautifully loaded with all the columns and rows, and the edit and delete...
1
2554
by: Froefel | last post by:
I'm very new to the ADO.NET and WebForms arena, so the problem that I'm having is probably trivial. Using VS2005, I'm just creating a small test project that has a text box allowing you to enter a SQL statement, a button to execute the statement and a GridView control to display the results. The GridVIew control should AllowPaging and AllowSorting. The data comes from a SQL datasource, which I access through a connection string stored in...
2
3136
by: Cirene | last post by:
I have a gridview that is filtered by a databound dropdownlist. I've set AppendDataBound to True and added the item "ALL" in the dropdownlist. My gridview is supposed to be filtered by this dropdownlist. When it's "ALL" I want to include everything. When it's something else I want to filter the gv data by this dropdownlist. Do I need to dynamically change the WHERE clause via code? I'm sure there's an easier way to do this.
2
9128
by: wildman | last post by:
RE: Gridview textbox has data check without postback.. javascript? I have a gridview with a textbox. I can set the textbox to autopostback and check for a value in a prerender event to decide if I should make a button on the grid row visible. However, the problem with autopostback on a textbox is the postback occurrs when you select another control or click away ( I guess). This is very awkward when the control selected is dropdown as...
0
8221
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8162
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8603
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8317
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8463
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
6104
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5560
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4154
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
1468
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.