claracruz
asked on
Dynamically list yers in dropdown
I need to generate a dropdownlist dynamically. the dropdown list whould have the list of next 10 yrs. like "2003","2004","2005","2006 ","2007"," 2008","200 9","2010", "2011","20 12"
the years are based on current yr.(start from)
Anyone can guide me on this?
Also is there anywhere I can do this and use the ObjectDataSource to populate the list
Thanks
the years are based on current yr.(start from)
Anyone can guide me on this?
Also is there anywhere I can do this and use the ObjectDataSource to populate the list
Thanks
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
I like to write by such way for readability. No problem, if you want to save code line, in any case this produces the same executable code.
ASKER
Thanks for that guus,
As do I apply your above code to the following;-
<asp:DropDownList ID="year" runat="server" CssClass="input" Width="140px">
<asp:ListItem Text=" ----- Any Year ------ "/>
<asp:ListItem Text="2006"/>
<asp:ListItem Text="2005"/>
<asp:ListItem Text="2004"/>
<asp:ListItem Text="2003"/>
</asp:DropDownList>
bearing in mind am trying to seperate code from presentation
As do I apply your above code to the following;-
<asp:DropDownList ID="year" runat="server" CssClass="input" Width="140px">
<asp:ListItem Text=" ----- Any Year ------ "/>
<asp:ListItem Text="2006"/>
<asp:ListItem Text="2005"/>
<asp:ListItem Text="2004"/>
<asp:ListItem Text="2003"/>
</asp:DropDownList>
bearing in mind am trying to seperate code from presentation
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
thanks for the bit of code, I used it to bind to the dropdown from codebehind link so;-
<asp:DropDownList ID="ddyear" runat="server" CssClass="input" Width="140px"></asp:DropDo wnList>
Then in my codebehind;-
protected void loadPage(object sender, EventArgs e)
{
if (!IsPostBack)
{
String[] Array1 = new string[20];
int nIntial = 2006;
Array1[0] = " ---- Any Year ---- ";
for (int i = 1; i < Array1.Length; i++)
{
Array1[i] = (nIntial--) + "";
}
ddyear.DataSource = Array1;
ddyear.DataBind();
}
}
<asp:DropDownList ID="ddyear" runat="server" CssClass="input" Width="140px"></asp:DropDo
Then in my codebehind;-
protected void loadPage(object sender, EventArgs e)
{
if (!IsPostBack)
{
String[] Array1 = new string[20];
int nIntial = 2006;
Array1[0] = " ---- Any Year ---- ";
for (int i = 1; i < Array1.Length; i++)
{
Array1[i] = (nIntial--) + "";
}
ddyear.DataSource = Array1;
ddyear.DataBind();
}
}
for ( int i = 0; i < 10; i++ )
{
comboBox1.Items.Add(year.T
++year;
}