Click here to Skip to main content
16,018,818 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Please tell me what is wrong in this code.

XML
<asp:DropDownList ID="ddlFromYear" runat="server" SkinID="DDLSmall">
                                                                    <asp:ListItem Text='<%= System.DateTime.Now.Year %>' Value="1"></asp:ListItem>
                                                                    <asp:ListItem Text='<%= System.DateTime.Now.Year-1 %>' Value="2"></asp:ListItem>
                                                                </asp:DropDownList>



I am not getting year, it is printing the expression at runtime.

Thanks,
Jagjot
Posted

1 solution

Can't you try with inserting the ListItems in for the dropdown?
Try this:
C#
ddlFromYear.Items.Insert(0, new ListItem(System.DateTime.Now.Year.ToString(), "1"));
ddlFromYear.Items.Insert(1, new ListItem((System.DateTime.Now.Year-1).ToString(), "2"));


--Amit
 
Share this answer
 
v2
Comments
Jagjot Singh 1-Oct-12 7:15am    
Thanks for your solution. I want to know that why it is not working in direct HTML.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900