Filling Dropdownlist
dynamically with the range of 1900 to this Year, for that
write the following code
in PageLoad:
protected void Page_Load(object
sender, EventArgs e)
{
if (!Page.IsPostBack)
{
int
thisYear = Convert.ToInt32(System.DateTime.Now.Year);
for
(int i = 1999; i <= thisYear; i++)
{
ddlYear.Items.Add(new ListItem(i.ToString(),
i.ToString()));
}
ListItem
lsitem = new ListItem("Select Year", "0");
ddlYear.Items.Insert(0, lsitem);
}
}
while converting to datatype int it through an exception so try this code to get the year value from DateTime
ReplyDeleteDateTime today=System.DateTime.Now;
int j=today.Year;
Sorry for error... Now i have changed my code for converting datatype. use the above code it will help you...
Deletehi try this also ..http://codingresolved.com/discussion/68/how-to-fill-year-list-in-dropdownlist#Item_2
ReplyDelete